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

DURGESH

I Love python, so I like machine learning a Lot and on the other hand, I like building apps and fun games I post blogs on my website for Tech enthusiast to learn and Share Information With The World.

Leave a Reply

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

twelve − 2 =

Recent Content