int p, r, m, n, temp;
printf("请输入两个正数:\n");
scanf_s("%d,%d",&m,&n);
if (n < m)
{
temp = n;
n = m;
m = temp;
}
p = n * m;
while (m != 0)
{
r = n % m;
n = m;
m=r;
}
printf("它们的最大公约数:%d",n);
printf("它们的最小公倍数为:%d\n",p/n);
#include <stdio.h>
int main() {
int p, r, m, n, temp;
printf("请输入两个正数:\n");
scanf_s("%d,%d",&m,&n);
// 假设输入的是10,5 则m = 10,n = 5;
if (n < m) //5<10 成立
{
temp = n;
//把n的值赋给temp,此时temp=5,n=5,m=10
n = m;
//把m的值赋给n,此时temp=5,n=10,m=10
m = temp;
//把temp的值赋给m,此时temp=5,n=10,m=5
//temp相当于工具人,把m与n的值互换
}// 确保n为大值
p = n * m;
// p = 5 * 10 = 50; n = 10; m = 5;
while (m != 0) //m!=0 成立
{
r = n % m;
//r = 10 % 5 = 0
n = m;
//把m的值赋给n,此时r = 0, n = 5, m = 5;
m=r;
//把r的值赋给m,此时 r = 0; m = 0; n = 5; p = 50;
}// 运算
printf("它们的最大公约数:%d",n);
printf("它们的最小公倍数为:%d\n",p/n);
return 0;
}