Write a program find LCM and HCF in c Language

 

// find HCF and LCM of Two Number

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

int  main()
{
int a, b, s, hcf, i, lcm;
clrscr();

printf(  " Enter first Numbers : " );
scanf( "%d", &a );
printf(" \nEnter second number : ");
scanf("%d",&b);

if(a < b)
s = a;
else
s = b;

for(i=1 ; i<=s ; i++)
{
if((a%i == 0) && (b%i == 0))
{
hcf = i;
}
}

printf( "\nHCF of given Numbers is = %d", hcf );
lcm = (a * b) / hcf;
printf( "\n\nLCM of given Numbers is = %d", lcm );

getch();
return 0;
}

Output:

Enter first Numbers : 16

Enter second number : 24

HCF of given Numbers is = 8

LCM of given Numbers is = 48

Reactions

Post a Comment

0 Comments