WRITE A C PROGRAM TO FIND THE HCF OF TWO NUMBERS
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2;
printf("Enter two numbers:");
scanf("%d%d",&n1,&n2);
while(n1!=n2)
{
if(n1>n2)
n1=n1-n2;
else
n2=n2-n1;
}
printf("The HCF is %d",n1);
getch();
}
Output:
Enter two numbers:
4
8
The HCF is 4
If we know LCM or HCF of two numbers, then we can find the other one using below equation.
ReplyDeleteLCM(A, B) X HCF(A, B) = A*B