H.C.F. means Highest Common Factor. By the help of HCF we try to find any largest number which can divide both the number.
For Example :
H.C.F of 20 and 30.
Both number 20 and 30 are divisible by 1,2,5,10.
H.C.F = max( 1, 2, 5, 10 )
Here is the C program to find the HCF( Highest Common Factor) as below.
Source Code to find H.C.F.
#include<stdio.h>
void main()
{
int n1,n2;
clrscr();
printf("\nEnter first number:");
scanf("%d",&n1);
printf("\nEnter second number::");
scanf("%d",&n2);
while(n1!=n2)
{
if(n1>=n2-1)
n1=n1-n2;
else
n2=n2-n1;
}
printf("\nGCD/HDF=%d",n1);
getch();
}
0 comments:
Post a Comment