Showing posts with label Program to calculate GCD using recursion. Show all posts
Showing posts with label Program to calculate GCD using recursion. Show all posts

Program to calculate GCD using recursion


Program to calculate GCD using recursion
Program
#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;
}