【C语言】 输入两个正整数m和n,求其最大公约数(GCD)和最小公倍数(LCM)

[提示:数学上,GCD=(m*n)/LCM)]请问哪里有错误呢?按图片上的提交,显示的LCM=n,GCD=m(m,n为原始输入值)非伸手党。想知道自己错在哪里,只会甩答案... [提示:数学上,GCD=(m*n)/LCM)]

请问哪里有错误呢?
按图片上的提交,显示的LCM=n,GCD=m(m,n为原始输入值)
非伸手党。想知道自己错在哪里,只会甩答案的人...抱歉
我用的是GUIDE
展开
 我来答
a1012144015
推荐于2016-10-26 · TA获得超过6415个赞
知道大有可为答主
回答量:9038
采纳率:40%
帮助的人:1275万
展开全部
#include
int main()
{
int m, n;
int m_cup, n_cup, res; /*被除数, 除数, 余数*/
printf("Enter two integer:\n");
scanf("%d %d", &m, &n);
if (m > 0 && n >0)
{
m_cup = m;
n_cup = n;
res = m_cup % n_cup;
while (res != 0)
{
m_cup = n_cup;
n_cup = res;
res = m_cup % n_cup;
}
printf("Greatest common divisor: %d\n", n_cup);
printf("Lease common multiple : %d\n", m * n / n_cup);
}
else printf("Error!\n");
return 0;
}
更多追问追答
追问
我不是伸手党...我是想知道自己的错误
追答
好,我看看
int m,n,l,g,i;
printf("nput teo shuzi");
scanf("%d %d",&m,&n);
i=1;
while(n%m!=0){
i++;
n=n*i;
}
l=n;
g=(m*n)/l;
printf("Lcm is %d,Gcd is %d",l,g);
我改好了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式