Write a C program to find HCF & LCM of two numbers
# include<stdio.h>
int hcf(int n1,int n2)
{
int r;
while(n2!=0)
{
r=n1%n2;
n1=n2;
n2=r;
}
return n1;
}
int lcm(int m , int h)
{
int l =m/h;
return l;
}
int main ()
{
int n1,n2,h,l,m;
printf("enter the first number = ");
scanf("%d",&n1);
printf("enter the second number = ");
scanf("%d",&n2);
h=hcf(n1,n2);
printf(" HCF of %d , %d is %d ",n1,n2,h);
m=n1*n2;
l=lcm(m,h);
printf("\n LCM of %d , %d is %d ",n1,n2,l);
}
OUTPUT :
Post a Comment
0 Comments