#include <stdio.h>
int hcf(int, int);
void main()
{
int h, i, a, b;
printf("\nEnter values of two numbers: ");
scanf("%d %d", &a, &b);
h = hcf(a, b);
printf("\nHCF of numbers is: %d", h);
getch();
}
int hcf(int a, int b)
{
if (a%b == 0)
return b;
else
return hcf(b, a%b);
}
C++ Program to Find HCF of two numbers
ReplyDeleteTo find the HCF or GCD of two or more numbers, make prime factors of the numbers and choose the common prime factors. Then the take the highest common factor this highest common factor is HCF of number.