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.

Program

#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

error: Alert: Content is protected!!