TheAlgorithms-C/math/gcd.c

18 lines
278 B
C
Raw Normal View History

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