Write C++ Program to Find G.C.D Using Recursion
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream>
using namespace std;
int hcf(int n1, int n2);
int main()
{
int n1, n2;
cout << "Enter two positive integers: ";
cin >> n1 >> n2;
cout << "H.C.F of " << n1 << " & " << n2 << " is: " << hcf(n1, n2);
return 0;
}
int hcf(int n1, int n2)
{
if (n2 != 0)
return hcf(n2, n1 % n2);
else
return n1;
}
|

Post a Comment