2020-02-29 18:06

# 本题要求两个给定正整数的最大公约数和最小公倍数，求大神帮忙改改，谢谢

511 292

73 2044

#include
using namespace std;
int main()
{
double num1,num2,number1,number2,i,number,j,m,k,flag=0;
cin>>num1>>num2;
if(num1>num2)
{
number1=num1;
number2=num2;
}
else
{number1=num2;
number1=num1;
}
for(i=number2;i>0;i--)
{
if(num1/number2==0&&num2/number2==0)
{
cout<<i;
break;
}
}
number=num1*num2;
j=number1;
m=number2;
i=1;
k=1;
while(j<=number){
while(m<=j)
{
if(m==j)
{cout<<m;
flag=1;
break;
}
k++;
m*=k;

}
if(flag==1)
break;
i++;

j*=i;
}

}

• 写回答
• 好问题 提建议
• 追加酬金
• 关注问题
• 邀请回答

#### 2条回答默认 最新

• threenewbee 2020-02-29 20:47
最佳回答
``````// Q1056566.cpp : Defines the entry point for the console application.
//

#include <iostream>
using namespace std;
int main()
{
int num1,num2,number1,number2,i,number,j,m,k,flag=0;
cin>>num1>>num2;
if(num1>num2)
{
number1=num1;
number2=num2;
}
else
{
number1=num2;
number2=num1;
}
for(i=number2;i>0;i--)
{
if(number1%i==0 && number2%i==0)
{
cout<<i << " " << num1 / i * num2;
break;
}
}
/*
number=num1*num2;
j=number1;
m=number2;
i=1;
k=1;
while(j<=number){
while(m<=j)
{
if(m==j)
{
cout<<m;
flag=1;
break;
}
k++;
m*=k;

}
if(flag==1)
break;
i++;

j*=i;
}*/
}

``````
评论
解决 无用
打赏 举报