# include < stdio.h>
int gcd(int,int);
void main()
{
int x,y,z,gc;
clrscr();
printf("\nEnter three numbers:");
scanf("%d%d%d",&x,&y,&z);
if(x>y)
gc=gcd(x,y);
else
gc=gcd(y,x);
if(gc>z)
gc=gcd(gc,z);
else
gc=gcd(z,gc);
printf("\nGCD of %d, %d and %d =%d",x,y,z,gc);
getch();
}
int gcd(int n,int m)
{
int c;
while(1)
{
if(n%m==0)
break;
else
{
c=n%m;
n=m;
m=c;
}
}
return m;
}
No comments:
Post a Comment