设计C++问题

来源:百度知道 编辑:UC知道 时间:2024/06/18 15:23:57
编写程序,求输入的两个正整的最大公约数,和最小公倍数

#include <iostream>
using namespace std;
int main()
{
int p,r,n,m,temp;
cout<<"please enter two positive integer numbers n,m:";
cin>>n>>m;
if(n<m) //大数放在n中,小数放在m中;
{
temp=n;
n=m;
m=temp;
}
p=n*m; //先将n和m的乘积保存在P中,以便求最小公倍数用
while(m!=0)
{
r=n%m; //求n和m的最大公约数
n=m;
m=r;
}
cout<<"HCF="<<n<<endl;
cout<<"LCD="<<p/n<<endl;
return 0;
}
本题用了碾转相除法 C++课有说的,本人水平有限,请多多指教