Problem statement
Write a program which takes two numbers as input from user and find the HCF of numbers.
What is HCF
HCF stands for Highest Common Factor(HCF).
HCF is also known as Greatest Common Measure(GCM) and Greatest Common Divisor(GCD)
HCF of two or more numbers is the greatest number which divides each of them exactly.
For example: HCF of 60 and 75 is 15.
C program to find HCF of two given numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include<stdio.h> int main() { int num1, num2, i=2; printf("Enter any two numbers\n"); scanf("%d %d", &num1, &num2); i = num1; while(i > 1) { if(num1%i == 0 && num2%i == 0) { break; } i--; } printf("HCF of %d and %d is %d", num1, num2, i); } |
Output
1 2 3 |
Enter any two numbers 60 75 HCF of 60 and 75 is 15 |