Header Ads Widget

Write a CPP function to calculate HCF of two numbers

 Code:-

#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,m;
cout<<"Enter two numbers\n";
cin>>a>>b;
m=min(a,b);
while(1)
{
if(a%m==0 && b%m==0)
break;
m--;
}
cout<<"HCF of "<<a<<" and "<<b<<" is : "<<m;
return 0;
}

Output:-

Enter two number
12 8
HCF of 12 and 8 is : 4




Post a Comment

0 Comments