Created
July 9, 2018 13:22
-
-
Save lalabuy948/50595206f94431e777c07eb916c59d2f to your computer and use it in GitHub Desktop.
Calculate the greatest common divisor of two given numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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