/*............PROGRAM FOR GCD OF TWO NUMBERS..............*/
void main()
{
int a,b,gcd;
clrscr();
printf("Enter two numbers");
scanf("%d%d",&a,&b);
gcd=recgcd(a,b);
printf("GCD of %d and %d is=%d",a,b,gcd);
getch();
}
int recgcd(int x,int y)
{
int r;
if(y==0)
{
return(x);
}
else
{
r=x%y;
return(recgcd(y,r));
}
}
void main()
{
int a,b,gcd;
clrscr();
printf("Enter two numbers");
scanf("%d%d",&a,&b);
gcd=recgcd(a,b);
printf("GCD of %d and %d is=%d",a,b,gcd);
getch();
}
int recgcd(int x,int y)
{
int r;
if(y==0)
{
return(x);
}
else
{
r=x%y;
return(recgcd(y,r));
}
}
No comments:
Post a Comment