147. C Program to find G.C.D of given numbers using recursion.
How does this program work?
- In this C programme you will learn about how to find G.C.D of given numbers using recursion.
Here is the code
#include <stdio.h>
int gcd(int, int);
int main()
{
int a, b, result;
//User inputs
printf("Enter 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 );
//To display output
}
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;
}