Program to find HCF & LCM of two numbers in C

Source Code

// 20. Program to find HCF & LCM of two numbers
// Arpan Das - CST 2nd Year (VOCLET)

#include <stdio.h>
//#include <conio.h>

int main() {
	int x, y, product;
	//clrscr();
	printf("Please enter any two numbers: \n");
	scanf("%d%d", &x, &y);
	product = x*y;
	while (x!=y) {
		if (x>y) x -= y;
		else y -= x;
	}
	printf("\nH.C.F. is %d", x);
	printf("\nL.C.M. is %d", product/x);
	//getch();
}

Output

Please enter any two numbers: 
64 24

H.C.F. is 8
L.C.M. is 192

Leave a Reply

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