Skip to content

Instantly share code, notes, and snippets.

@sujimodern
Last active July 6, 2019 05:49
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 sujimodern/5a38b7d3771236dc87db2fe27dcf8fa2 to your computer and use it in GitHub Desktop.
Save sujimodern/5a38b7d3771236dc87db2fe27dcf8fa2 to your computer and use it in GitHub Desktop.
Euclidean algorithm in c
#include <stdio.h>
int gcd(int a, int b) {
int r;
for (;;) {
r = a % b;
if (!r)
break;
a = b;
b = r;
}
return b;
}
int main() {
int a = 5796;
int b = 7935;
int r = gcd(a, b);
printf("%d\n", r);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment