write a c program to find hcf (gcd) of two numbers,write a c program gcd of two numbers,write a c program to find gcd of two numbers,write a c program to find gcd in the given two numbers using while loop
Write a c program to find gcd and lcm of two numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,gcd,lcm,r,n,d;
clrscr();
printf("Enter two numbers: ");
scanf("%d%d",&n1,&n2);
if(n1>n2)
{
n=n1;
d=n2;
}
else
{
n=n2;
d=n1;
}
r=n1%n2;
while(r!=0)
{
n=d;
d=r;
r=n%d;
}
gcd=d;
lcm=n1*n2/gcd;
printf("GCD of %d and %d=%d\n",n1,n2,gcd);
printf("LCM of %d and %d=%d\n",n1,n2,lcm);
getch();
}
Output:
Enter two numbers: 4
2
GCD of 4 and 2=2
No comments: