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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Greatest common divisor step by step in the Simula 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 Simula programming language

Source code in the simula programming language

BEGIN
    INTEGER PROCEDURE GCD(a, b); INTEGER a, b;
    BEGIN
        IF a = 0 THEN a := b
        ELSE
            WHILE 0 < b DO BEGIN INTEGER i;
                i := MOD(a, b); a := b; b := i;
            END;
        GCD := a
    END;

    INTEGER a, b;
    !outint(SYSOUT.IMAGE.MAIN.LENGTH, 0);!OUTIMAGE;!OUTIMAGE;
    !SYSOUT.IMAGE :- BLANKS(132);  ! this may or may not work;
    FOR b := 1 STEP 5 UNTIL 37 DO BEGIN
        FOR a := 0 STEP 2 UNTIL 21 DO BEGIN
            OUTTEXT("  ("); OUTINT(a, 0);
            OUTCHAR(','); OUTINT(b, 2);
            OUTCHAR(')'); OUTINT(GCD(a, b), 3);
        END;
        OUTIMAGE
    END
END

  

You may also check:How to resolve the algorithm Fractal tree step by step in the Plain English programming language
You may also check:How to resolve the algorithm List comprehensions step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Pentomino tiling step by step in the Nim programming language
You may also check:How to resolve the algorithm Arithmetic derivative step by step in the Perl programming language
You may also check:How to resolve the algorithm Greatest common divisor step by step in the Frink programming language