How to resolve the algorithm Greatest common divisor step by step in the Objeck programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Greatest common divisor step by step in the Objeck 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 Objeck programming language
Source code in the objeck programming language
bundle Default {
class GDC {
function : Main(args : String[]), Nil {
for(x := 1; x < 36; x += 1;) {
IO.Console->GetInstance()->Print("GCD of ")->Print(36)->Print(" and ")->Print(x)->Print(" is ")->PrintLine(GDC(36, x));
};
}
function : native : GDC(a : Int, b : Int), Int {
t : Int;
if(a > b) {
t := b; b := a; a := t;
};
while (b <> 0) {
t := a % b; a := b; b := t;
};
return a;
}
}
}
You may also check:How to resolve the algorithm User input/Text step by step in the smart BASIC programming language
You may also check:How to resolve the algorithm Arrays step by step in the Ada programming language
You may also check:How to resolve the algorithm Draw a sphere step by step in the Maxima programming language
You may also check:How to resolve the algorithm Non-decimal radices/Input step by step in the Tcl programming language
You may also check:How to resolve the algorithm Modular exponentiation step by step in the Ada programming language