输入两个正整数m,n。求其最大公约数和最小公倍数。

来源:百度知道 编辑:UC知道 时间:2024/05/25 12:13:00

#include <stdio.h>
//求最大公约数
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 <= 1 || n <= 1)
{
printf("Values should be larger than 1");
continue;
}
int a = (m > n) ? m : n;
int b = (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;
}

# include<stdio.h>
# include<conio.h>
void main()
{
int a,b,c,d,temp;
printf(