GCD of 2 numbers

Program to find the GCD of 2 numbers using the Euclid's algorithm.


#include<stdio.h>
#include<conio.h>
main()
{
int a,b,m,n,r;
clrscr();
printf("Enter the two nos\n");
scanf("%d%d",&a,&b);
if(a>b)
{
m=a;
n=b;
}
else
{
m=b;
n=a;
}
r=m%n;
while(r!=0)
{
m=n;
n=r;
r=m%n;
}
printf("GCD of %d and %d is %d",a,b,n);
getch();
return 0;
}

Category:

0 comments: