📅  最后修改于: 2020-09-25 06:09:34             🧑  作者: Mango
该程序从用户处获取两个正整数,然后使用递归计算GCD 。
访问此页面以了解如何使用循环来计算GCD 。
#include
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;
}
输出
Enter two positive integers: 366 60
H.C.F of 366 and 60 is: 6