【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 展开
请问哪里有错误呢?
按图片上的提交,显示的LCM=n,GCD=m(m,n为原始输入值)
非伸手党。想知道自己错在哪里,只会甩答案的人...抱歉
我用的是GUIDE 展开
展开全部
#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 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);
我改好了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询