How to resolve the algorithm Greatest common divisor step by step in the AppleScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Greatest common divisor step by step in the AppleScript 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 AppleScript programming language
Source code in the applescript programming language
-- gcd :: Int -> Int -> Int
on gcd(a, b)
if b ≠ 0 then
gcd(b, a mod b)
else
if a < 0 then
-a
else
a
end if
end if
end gcd
on hcf(a, b)
repeat until (b = 0)
set x to a
set a to b
set b to x mod b
end repeat
if (a < 0) then return -a
return a
end hcf
You may also check:How to resolve the algorithm String concatenation step by step in the DCL programming language
You may also check:How to resolve the algorithm 24 game step by step in the Arturo programming language
You may also check:How to resolve the algorithm Get system command output step by step in the Arturo programming language
You may also check:How to resolve the algorithm Knuth shuffle step by step in the ACL2 programming language
You may also check:How to resolve the algorithm Leap year step by step in the Objeck programming language