//Program to find G.C.D. (Greatest Common Divisor) / H.C.F. (Highest Common Factor) of two numbers.
#include <stdio.h>
#include <conio.h>
void main()
{
int num1, num2, min,i;
clrscr(); //for clearing the console screen
//Taking input
printf("Enter
two integers: ");
scanf("%d
%d", &num1, &num2);
//Logic for finding GCD/HCF
if(num1>num2) //getting the minimum number
{
min=num2; //minimum value is stored in variable min
}
else
{
min=num1; //minimum value is stored in variable min
}
for(i=min; i>=1; i--)
{
if(num1%i==0 &&
num2%i==0)
{
printf("HCF
of %d and %d is %d", num1, num2,i);
break;
}
}
getch(); //for holding the console screen
}
No comments:
Post a Comment