Search



Tuesday, 17 February 2015

LCM-HCF

In this program, we have to find Least common factor & highest common factor ( L.C.M & H.C.F ) . As , the name suggests two no.s a & b will be given out of which we have to find lcm & hcf & also lcm = (a*b) / hcf . the while loop is used to find hcf..


Program to find LCM-HCF.

#include<stdio.h>
#include<conio.h>
void main()
{ int x,y,a,b,hcf,lcm,temp;
clrscr();
printf("\n program to find L.C.M & H.C.F (of 2 no.s x & y)");
printf("\n\n enter x : ");
scanf("%d",&x);
printf("\n enter y : ");
scanf("%d",&y);
a=x; b=y;
while(b!=0)
{ temp = b;
b = a%b;
a = temp;
}
hcf = a;
lcm = (x*y)/hcf;
printf("\n\n H.C.F = %d",hcf);
printf("L.C.M = %d",lcm);
getch();
}


No comments:

Post a Comment

Guys if you think something is wrong or should be edit than please do comment.