The following C program using iteration finds the HCF of two entered integers. The HCF stands for Highest Common Factor.

Here is the source code of the C program to find the HCF of two entered integers. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C Program to find HCF of a given Number without using Recursion`

`*/`

`#include <stdio.h>`

int hcf(int, int);

int main()

`{`

int a, b, result;

printf("Enter the two numbers to find their HCF: ");

scanf("%d%d", &a, &b);

result = hcf(a, b);

printf("The HCF of %d and %d is %d.\n", a, b, result);

return 0;

`}`

int hcf(int a, int b)

`{`

while (a != b)

`{`

if (a > b)

`{`

a = a - b;

`}`

`else`

`{`

b = b - a;

`}`

`}`

return a;

`}`

advertisements

$ cc pgm31.c $ a.out Enter the two numbers to find their HCF: 24 36 The HCF of 24 and 36 is 12.

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.