Write C program to find HCF of two numbers.

Highest Common Factor (H.C.F.) of two natural numbers is the largest common factor (or divisor) of the given natural numbers. The Highest Common Factor is also known as
the greatest common factor (gcf).

For example, the hcf of 54 and 24 is 6

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <stdio.h> int main() { int i, num1, num2, min, HCF=1; //Read two numbers from user printf("Enter any two numbers: "); scanf("%d%d", &num1, &num2); // Find min number between two numbers min = (num1<num2) ? num1 : num2; for(i=1; i<=min; i++) { if(num1%i==0 && num2%i==0) { HCF = i; } } printf("HCF of %d and %d = %d\n", num1, num2, HCF); return 0; } |

10 July 2019 2329
Written By: **Rohit**

© 2020 Tech Study. All rights reserved | Developed by Tech Study| Privacy Policy | Sitemap