TheAlgorithms-C/misc/GCD.c

16 lines
276 B
C
Raw Normal View History

2017-10-19 16:04:14 +08:00
#include <stdio.h>
// Euclid's algorithm
int GCD(int x, int y) {
2017-10-19 16:19:44 +08:00
if (y == 0)
2017-10-19 16:04:14 +08:00
return x;
2017-10-19 16:19:44 +08:00
return GCD(y, x%y);
2017-10-19 16:04:14 +08:00
}
int main() {
int a, b;
printf("Input two numbers:\n");
scanf("%d %d", &a, &b);
printf("Greatest common divisor: %d\n", GCD(a, b));
}