C Program to Calculate GCD using recursion

How to write a C Program to calculate Greatest Common Divisor using recursion in C Programming Language ?

Solution For C Program :

/*C Program to calculate Greatest Common Divisor using recursion.*/

#include<stdio.h>
void main()
{
int gcd(int,int);
int a, b, result;
printf("\nEnter Any Two Values : ");
scanf("%d%d", &a, &b);
result = gcd(a, b);
printf("\nThe GCD of %d and %d is %d.", a, b, result);
}
int gcd(int x, int y)
{
int temp, n;
temp = x % y;
if(temp != 0)
{
n = gcd(y, temp);
return(n);
}
if(temp == 0)
return y;
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable


Learn More :