Skip to content

Instantly share code, notes, and snippets.

@lalabuy948
Created July 9, 2018 13:22
Show Gist options
  • Save lalabuy948/50595206f94431e777c07eb916c59d2f to your computer and use it in GitHub Desktop.
Save lalabuy948/50595206f94431e777c07eb916c59d2f to your computer and use it in GitHub Desktop.
Calculate the greatest common divisor of two given numbers
/* Calculate the greatest common divisor of two given numbers */
#include <stdio.h>
int gcd(int a, int b) {
int r;
while (b > 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
int x, y;
while (scanf("%d %d", &x, &y) != EOF) {
if (x > 0 && y > 0){
printf("%d %d %d\n", x, y, gcd(x, y));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment