python输入两个正整数m和n求最大公约数
发布网友
发布时间:2022-05-31 02:28
我来回答
共1个回答
热心网友
时间:2023-10-06 08:12
#include
//求最大公约数
void GreatestCommonDivisor()
{
while (1)
{
int m = 0,n = 0;
printf("input m:\b");
scanf("%d",&m);
getchar();
printf("input n:\b");
scanf("%d",&n);
if (m == 0 || n == 0) return;
if (m n) n :m;
int c = 0;
while ((a % b) != 0)
{
c = a % b;
a = b;
b = c;
}
printf("%d and %d GreatestCommonDivisor = %d\n",m,n,b);
printf("%d and %d 最小公倍数为:%d\n",m,n,b/n);
}
}
int main()
{
GreatestCommonDivisor();
return 0;
}