Saturday, 5 May 2012

Recursive GCD in C


#include<stdio.h>
main()
{
int a,b,gcd;
printf("Enter the values of a and b\n");
scanf("%d%d",&a,&b);
gcd=f_GCD(a,b);
printf("The GCD of %d and %d = %d\n",a,b,gcd);
getch();
return 0;
}


f_GCD(int x,int y)
{
int rem;
if(y==0)
{
return(x);
}
else
{
rem=x%y;
}
return(f_GCD(y,rem));
}

No comments:

Post a Comment