Table of Contents
C program to find HCF
C program to find HCF : Highest Common Factor/GCD (Greatest Common Divisor) of two or more numbers is a highest integer which can divide them.
E.g. HCF of 12 and 18 is 6
Logic to find HCF in C
#include<stdio.h>
//itvoyagers.in
int hcf(int a, int b)
{
int l,i,hcf;
if(a<b)
{
l = a;
}
else
{
l = b;
}
for(i=1; i<=l; i++)
{
if((a % i == 0) && (b % i == 0))
{
hcf = i;
}
}
return hcf;
}
//itvoyagers.in
int main()
{
int x, y;
printf("Enter first number : ");
scanf("%d",&x);
printf("Enter second number : ");
scanf("%d",&y);
printf("HCF of %d and %d is %d",x,y,hcf(x,y));
return 0;
}
Output :
Enter first number : 48
Enter second number : 36
HCF of 48 and 36 is 12
PRACTICALS/PRACTICE PROGRAM IN C
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on Operator |
Easy Quiz on Operators in C part 1 |
Easy quiz on operators in C part 2 |
Easy quiz on operators in C part 3 |
Quizzes on Loops |
Easy quiz on loops in C part 1 |
Easy quiz on loops in C part 2 |
Easy quiz on loops in C part 3 |
Quizzes on Decision Making Statement |
Easy Quiz On Decision Making Statements Part 1 |
Easy Quiz On Decision Making Statements Part 2 |
Quizzes on String |
Easy quiz on String in C programming part 1 |
Quizzes on Array |
Easy quiz on Array in C programming – part 1 |
5 – Best Java program to convert decimal to binary |
New Quizzes Coming soon.. |
We are aiming to explain all concepts of C in easiest terms as possible.

ITVoyagers
Author