# HCF Of Two Numbers | C Program

## Write a  C program to find  HCF of Two Numbers

Here, in this page we will discuss HCF od two numbers in C . The HCF or the Highest Common Factor of two numbers is the largest common factor of two or more values. The HCF can be calculated using some simple mathematical tricks. The following algorithm will determine how a c program can calculate the HCF of two numbers. ## Algorithm :

• Take two variable from the user say a and b.
• Take one variable say H, which hold the HCF of the given two numbers.
• Run a loop from i=1 to max(a, b)
• Inside the loop if the current value of i divides a and b both then update H to i i.e,(H=i) ## C Program tocalculate HCF of two numbers

`#include <stdio.h> int main() {     int a, b, i, H=1;   printf("Enter two numbers ");   scanf("%d %d", &a,&b);     for(int i = 1; i <= a || i <= b; i++) {    if( a%i == 0 && b%i == 0 )      H = i;   }   printf("HCF = %d", H);   return 0;}`

## Output

```Enter Two numbers 12 18HCF = 6
``` • Highest Common Factor(HCF): C | C++Java
• Lowest Common Multiple (LCM) : C | C++ | Java
• Greatest Common Divisor : C | C++ | Java
• Binary to Decimal to conversion : C | C++ | Java
• Binary to Octal conversion : C | C++ | Java
• Decimal to Binary conversion: C | C++ | Java
• Decimal to octal Conversion: C | C++ | Java
• Octal to Binary conversion : C | C++ | Java
• Octal to Decimal conversion : C | C++ | Java
• Quadrants in which a given coordinate lies : C | C++ | Java
• Permutations in which n people can occupy r seats in a classroom : C | C++ | Java
• Maximum number of handshakes: C | C++ | Java
• Addition of two fractions: C | C++ | Java
• Replace all 0’s with 1 in a given integer : C | C++ | Java
• Can a number be expressed as a sum of two prime numbers
: C | C++ | Java