programming-examples/c/Recursion/C Program to Find GCD of given Numbers using Recursion.c
2019-11-15 12:59:38 +01:00

32 lines
617 B
C

/*
* C Program to find GCD of given Numbers using Recursion
*/
#include <stdio.h>
int gcd(int, int);
int main()
{
int a, b, result;
printf("Enter the two numbers to find their GCD: ");
scanf("%d%d", &a, &b);
result = gcd(a, b);
printf("The GCD of %d and %d is %d.\n", a, b, result);
}
int gcd(int a, int b)
{
while (a != b)
{
if (a > b)
{
return gcd(a - b, b);
}
else
{
return gcd(a, b - a);
}
}
return a;
}
}