Example
Input
Input first number: 12 Input second number: 30
Output
HCF of 12 and 30: 6
HCF (Highest Common Factor) is the greatest number that divides exactly two or more numbers. HCF is also known as GCD (Greatest Common Divisor) or GCF (Greatest Common Factor).
/**
* C program to find HCF of two numbers
*/
#include <stdio.h>
int main()
{
int i, num1, num2, min, hcf=1;
/* Input two numbers from user */
printf("Enter any two numbers to find HCF: ");
scanf("%d%d", &num1, &num2);
/* Find minimum between two numbers */
min = (num1<num2) ? num1 : num2;
for(i=1; i<=min; i++)
{
/* If i is factor of both number */
if(num1%i==0 && num2%i==0)
{
hcf = i;
}
}
printf("HCF of %d and %d = %d\n", num1, num2, hcf);
return 0;
}
/*
Output :
Enter any two numbers to find HCF: 12
30
HCF of 12 and 30 = 6
*/