How to resolve the algorithm Greatest common divisor step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Greatest common divisor step by step in the CLU programming language

Table of Contents

Problem Statement

Find the greatest common divisor   (GCD)   of two integers.

Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Greatest common divisor step by step in the CLU programming language

Source code in the clu programming language

gcd = proc (a, b: int) returns (int)
    while b~=0 do
        a, b := b, a//b
    end
    return(a)
end gcd

start_up = proc()
    po: stream := stream$primary_input()
    as: array[int] := array[int]$[18, 1071, 3528]
    bs: array[int] := array[int]$[12, 1029, 3780]
    for i: int in array[int]$indexes(as) do
        stream$putl(po, "gcd(" || int$unparse(as[i]) || ", "
            || int$unparse(bs[i]) || ") = "
            || int$unparse(gcd(as[i], bs[i])))
    end
end start_up

  

You may also check:How to resolve the algorithm Distance and Bearing step by step in the Pascal programming language
You may also check:How to resolve the algorithm Concurrent computing step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Apply a callback to an array step by step in the Ursala programming language
You may also check:How to resolve the algorithm Dice game probabilities step by step in the 11l programming language
You may also check:How to resolve the algorithm Factorial step by step in the Fancy programming language