Skip to content

Instantly share code, notes, and snippets.

@vtamara
Created January 12, 2023 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vtamara/82d8336880b42b0a553a10d9ce791add to your computer and use it in GitHub Desktop.
Save vtamara/82d8336880b42b0a553a10d9ce791add to your computer and use it in GitHub Desktop.
{-
TASK 1 - Greatest Common Divisor
Write a method that calculates the greatest common divisor between 2
integers greater than or equal to 1 and less than 1048576.
-}
() recv_internal() {
}
;; solution based on
;; https://people.cs.ksu.edu/~schmidt/301s14/Exercises/euclid_alg.html
(int) gcd(int a, int b) method_id {
int k = a;
int m = b;
if (b > a) {
k = b;
m = a;
}
;; k is max(a,b) and m = min(a,b)
while (m != 0) {
int r = k % m;
k = m;
m = r;
}
return k;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment