How to resolve the algorithm Greatest common divisor step by step in the ALGOL W programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Greatest common divisor step by step in the ALGOL W 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 ALGOL W programming language
Source code in the algol programming language
begin
% iterative Greatest Common Divisor routine %
integer procedure gcd ( integer value m, n ) ;
begin
integer a, b, newA;
a := abs( m );
b := abs( n );
while b not = 0 do begin
newA := b;
b := a rem b;
a := newA;
end;
a
end gcd ;
write( gcd( -21, 35 ) );
end.
You may also check:How to resolve the algorithm Prime conspiracy step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm User input/Text step by step in the NS-HUBASIC programming language
You may also check:How to resolve the algorithm Sequence: nth number with exactly n divisors step by step in the Haskell programming language
You may also check:How to resolve the algorithm Munchausen numbers step by step in the J programming language
You may also check:How to resolve the algorithm Count the coins step by step in the ZX Spectrum Basic programming language