/* Program to find G.C.D. (Greatest Common Divisor) / H.C.F. (Highest Common Factor) of two numbers using conditional programming. */
#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
min=(num1>num2)?num2: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