编程,c语言,从键盘输入三个数,求三个数的最大公约数和最小公倍数_百 ...
发布网友
发布时间:2024-10-18 11:28
我来回答
共2个回答
热心网友
时间:2024-11-07 06:14
#include <stdio.h>
int gcd(int a, int b)
{
int t;
while(b > 0)
{
a %= b;
t = b;
b = a;
a = t;
}
return a;
}
int lcm(int a, int b)
{
return a*b/gcd(a,b);
}
int gcd3(int a, int b, int c)
{
return gcd(gcd(a, b), c);
}
int lcm3(int a, int b, int c)
{
return lcm(lcm(a,b),c);
}
int main()
{
int a,b,c;
scanf("%d%d%d", &a,&b,&c);
printf("gcd = %d, lcm = %d\n", gcd3(a,b,c), lcm3(a,b,c));
return 0;
}
热心网友
时间:2024-11-07 06:14