HCF:
- HCF Stands For Higest Common Factor.
- HCF is also Known as GCD (Greatest Common Divisor).
- HCF of Two Number is defined as the Largest Number that Divides Both Numbers Completely with Remainder Zero.
- LCM Stands For Lowest Common Multiple.
- LCM of two Numbers Defined as the Smallest Number that is Multiple of both Numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int num1 , num2 , lcm , gcd , remainder , numerator , denominator ;
clrscr();
printf( "Enter two numbers\n");
scanf(" %d%d " , &num1 , &num2 );
if (num1 > num2)
{
numerator=num1;
denominator=num2;
}
else
{
numerator = num2 ;
denominator = num1 ;
}
remainder = num1 % num2;
while ( remainder != 0)
{
numerator = denominator;
denominator = remainder;
remainder = numerator % denominator;
}
gcd = denominator;
lcm = (num1 * num2 ) / gcd;
printf("GCD of %d and %d =%d\n" , num1, num2, gcd);
printf(" LCM of %d and %d= %d\n" , num1, num2, lcm);
getch();
}
Output:
Enter two numbers
5
15
GCD of 5 and 15 = 5
LCM of 5 and 15 = 15
0 Response to "Write a C Program to Compute the LCM and HCF of Two Numbers by using While Statement"
Post a Comment