以下为两种使用C语言实现求三个数最小公倍数的方法及代码:
### 方法一:先求两个数的最小公倍数,再与第三个数求最小公倍数
```c
#include <stdio.h>
// 求两个数的最小公倍数
int commut(int a, int b) {
int i;
for (i = a; ; i++) {
if (i % a == 0 && i % b == 0)
break;
}
return i;
}
int main() {
int a, b, c, result_1, result_2;
printf("请输入三个数,并按空格隔开\n");
scanf("%d%d%d", &a, &b, &c);
result_1 = commut(a, b);
result_2 = commut(result_1, c);
printf("%d和%d的公倍数是%d\n", a, b, result_1);
printf("%d,%d,%d的公倍数是%d\n", a, b, c, result_2);
return 0;
}
```
### 方法二:通过循环不断递增,直到找到能同时被三个数整除的数
```c
#include <stdio.h>
// 返回三个数的最小公倍数
int fun(int x, int y, int z) {
int j, t, n, m;
j = 1;
t = j % x;
m = j % y;
n = j % z;
while (t != 0 || m != 0 || n != 0) {
j = j + 1;
t = j % x;
m = j % y;
n = j % z;
}
return j;
}
int main() {
int x1, x2, x3, j;
printf("Input x1 x2 x3:");
scanf("%d%d%d", &x1, &x2, &x3);
printf("x1=%d,x2=%d,x3=%d\n", x1, x2, x3);
j = fun(x1, x2, x3);
printf("The minimal common multiple is:%d\n", j);
return 0;
}
```