# HCF Of Two Numbers | C Program

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

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.

### Working :-

Step 1. Start

Step 2. Define variables P and Q

Step 3. Develop a loop from 1 to the maximum value of P and Q.

Step 4. Check if both P and Q are completely divided by the same loop, if it does, store the number.

Step 5. Print the stored number as HCF.

Step 6. Stop ### C Program tocalculate HCF of two numbers

```#include <stdio.h>
int main() {  //for initialize variables
int a, b, i, hcf;
a = 12;
b = 16;
//find hcf of number
for(i = 1; i <= a || i <= b; i++) {
if( a%i == 0 && b%i == 0 )
hcf = i;
} //display hcf
printf("HCF = %d", hcf);
return 0;
}

```

### Output

```HCF = 4
``` • 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