Table of Contents

C Program to find HCF and LCM

Example
#include<conio.h>
#include<stdio.h>
void main()
{
int n1,n2,a,b,hcf,lcm;
printf("enter the number n1 and n2\n");
scanf("%d%d",&n1,&n2);
a=n1;
b=n2;
while(n1!=n2)
{
if(n1>n2)
{
n1=n1-n2;
}

else
{
n2=n2-n1;
}
}
printf("hcf=%d",n1);
hcf=n1;
lcm=(a*b)/hcf;
printf("lcm=%d",lcm);
getch();
}
Program Output

enter the number n1 and n2

5

8

hcf=1

lcm=40