Home Uncategorized Find the GCD of two given integers using Recursive Functions

Find the GCD of two given integers using Recursive Functions

SHARE

Write a C program To find the GCD (greatest common divisor) of two given integers using functions with Recurssion.

#include <stdio.h>
int GCD(int,int);
int main()
{
int a,b,c;
printf(“Enter two numbers :\n”);
scanf(“%d%d”,&a,&b);
c=GCD(a,b);
printf(“GCD of given number is: %d\n”,c);
return 0;
}
int GCD(int x,int y)
{
if(x<y)
{
x=x+y;
y=x-y;
x=x-y;
}
if(x%y==0)
return y;
else
return GCD(y,x%y);
}

Output:

Enter two number:
67 109
GCD of given number is : 1

Write a C program To find the GCD (greatest common divisor) of two given integers using functions with Non-Recurssion.

Back to the programs list.