How to resolve the algorithm Greatest common divisor step by step in the Oberon-2 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Greatest common divisor step by step in the Oberon-2 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 Oberon-2 programming language
Source code in the oberon-2 programming language
MODULE GCD;
(* Greatest Common Divisor *)
IMPORT
Out;
PROCEDURE Gcd(a,b: LONGINT):LONGINT;
VAR
r: LONGINT;
BEGIN
LOOP
r := a MOD b;
IF r = 0 THEN RETURN b END;
a := b;b := r
END
END Gcd;
BEGIN
Out.String("GCD of 12 and 8 : ");Out.LongInt(Gcd(12,8),4);Out.Ln;
Out.String("GCD of 100 and 5 : ");Out.LongInt(Gcd(100,5),4);Out.Ln;
Out.String("GCD of 7 and 23 : ");Out.LongInt(Gcd(7,23),4);Out.Ln;
Out.String("GCD of 24 and -112 : ");Out.LongInt(Gcd(12,8),4);Out.Ln;
Out.String("GCD of 40902 and 24140 : ");Out.LongInt(Gcd(40902,24140),4);Out.Ln
END GCD.
You may also check:How to resolve the algorithm Radical of an integer step by step in the Sidef programming language
You may also check:How to resolve the algorithm Sequence of non-squares step by step in the TI-89 BASIC programming language
You may also check:How to resolve the algorithm Unix/ls step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the Red programming language
You may also check:How to resolve the algorithm Delete a file step by step in the Component Pascal programming language