program calculate the hcf and lcm of two number in c-programming.
In this program , we will calculate the hcf and lcm of two numbers in c-program taking two inputs from the user .
In this program, we first calculate the hcf and with the hcf calculate the lcm of two numbers.
#include<Stdio.h>
#include<conio.h>
void main()
{
int a,b,h,l,i,lcm;
printf("enter the two number ");
scanf("%d %d",&a,&b);
l=a<b?a:b;
for(i=l;i>=1;i--)
if(a%i==0&&b%i==0)
break;
printf("the hcf of the number is %d",i);
lcm=(a*b)/i;
printf("\nhe lcm of the number is %d",lcm);
getch();
}
output:
enters two numbers:
a=12 and b=16
hcf=4 and lcm=48
No comments:
Post a Comment