用c语言while编写两个正整数的最大公约数和最小公倍数

如题所述

#include <stdio.h>
main()
{
int p,r,n,m,temp;
printf("请输入两个正整数n,m"); //这个地方运行时要注意,两个数字之间要用“,”割开。
scanf("%d,%d",&n,&m);
p=n*m;
if(n<m)
{temp=n;
n=m;
m=temp;
}

while(m!=0)
{
r=n%m;
n=m;
m=r;
}
printf("它们的最大公约数为:%d\n",n);
printf("他们的最小公倍数为:%d\n",p/n);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-11-28
#include
<stdio.h>
main()
{
int
p,r,n,m,temp;
printf("请输入两个正整数n,m");
//这个地方运行时要注意,两个数字之间要用“,”割开。
scanf("%d,%d",&n,&m);
p=n*m;
if(n<m)
{temp=n;
n=m;
m=temp;
}
while(m!=0)
{
r=n%m;
n=m;
m=r;
}
printf("它们的最大公约数为:%d\n",n);
printf("他们的最小公倍数为:%d\n",p/n);
}
相似回答