codescracker


c

C Program to Find HCF and LCM of Two Numbers



« Previous Program Next Program »


Find HCF and LCM of Two Numbers in C

To find the HCF and LCF of two number in C programming, you have to ask to the user to enter the two numbers, to find the HCF and LCF of the two number to display the value of the HCF and LCM of the two numbers

C Programming Code to Find HCF and LCM of Two Numbers

Following C program ask to the user to enter any two number to find HCF & LCM, then display the result on the screen :

/* C Program - Find HCF and LCM of Two Numbers */#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int a, b, x, y, t, hcf, lcm;
	printf("Enter two number : ");
	scanf("%d%d",&x, &y);
	a=x;
	b=y;
	while(b!=0)
	{
		t=b;
		b=a%b;
		a=t;
	}
	hcf=a;
	lcm=(x*y)/hcf;
	printf("HCF = %d\n",hcf);
	printf("LCM = %d",lcm);
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program find hcf lcm

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test