C Program to Find LCM and HCF of Two Numbers

Here you will get C program to find lcm and hcf of two given numbers.

#include<stdio.h>

int main()
{
	int a,b,hcf,lcm,max,min,r;
	printf("Enter two numbers:");
	scanf("%d%d",&a,&b);
	
	if(a>b)
	{
		max=a;
		min=b;
	}
	else
		if(b>a)
		{
			max=b;
			min=a;
		}
	
	if(a==b)
		hcf=a;
	else
	{
		do
		{
			r=max%min;
			max=min;
			min=r;
		}while(r!=0);
		
		hcf=max;
	}
	
	lcm=(a*b)/hcf;
	
	printf("\nLCM=%d\nHCF=%d",lcm,hcf);

	return 0;
}

 

Output

Enter two numbers:4 7

LCM=28
HCF=1

Leave a Comment

Your email address will not be published. Required fields are marked *