Find HCF(gcd) of two number:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,num1,num2,temp,HCF=1;
clrscr();
printf("Enter Any Two Numbers To Find HCF:- ");
scanf("%d%d",&num1,&num2);
temp=(num1<num2)?num1:num2;
for(i=1;i<=temp;i++)
{
if(num1%i==0 && num2%i==0)
{
HCF=i;
}
}
printf("HCF of %d and %d=%d\n",num1,num2,HCF);
getch();
}
Output:
EmoticonEmoticon