Program To Calculate HCF of Two Numbers:
#include<iostream>
using namespace std;
main()
{
int num1,num2,min,hcf,i;
cout<<"Enter Two Numbers To Find HCF\n";
cin>>num1>>num2;
min=(num1<num2)? num1:num2;
for(i=1;i<=min;i++)
{
if(num1%i==0&&num2%i==0)
{
hcf=i;
}
}
cout<<"\nHighest Common Factor is "<<hcf;
return 0;
}
#include<iostream>
using namespace std;
main()
{
int num1,num2,min,hcf,i;
cout<<"Enter Two Numbers To Find HCF\n";
cin>>num1>>num2;
min=(num1<num2)? num1:num2;
for(i=1;i<=min;i++)
{
if(num1%i==0&&num2%i==0)
{
hcf=i;
}
}
cout<<"\nHighest Common Factor is "<<hcf;
return 0;
}