G.C.D., greatest common divisor using recursive function in C




//greatest common divisor using recursive function

#include
#include
int gcd(int ,int);

int main(void)
{
int x,y,z;
printf("Please Enter two integers:\n");
scanf ("%d%d",&x,&y);
z=gcd(x,y);
printf("Greatest Common Divisor of %d and %d is:%d\n",x,y,z);
getch();
return 0;
}
int gcd(int p,int q)
{
int r,greater,smaller;
if (p>q)
greater=p,smaller=q;
else
greater=q,smaller=p;
if(smaller==0)
return greater;
else
r=gcd(smaller,greater%smaller);
return r;
}




1 comment: