输入的开始是一个正整数,后面接着n个正整数,程序要计算出这n个正整数的最小公倍数,输出后面带有空行
#include <stdio.h>
#include <iostream>
using namespace std;
int x_y(int x, int y);
int main()
{
int i, n, a[1111], s;
while (scanf("%d", &n) != EOF)
{
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
if (n == 1)
printf("%d\n", a[0]);
else
{
s = x_y(a[0], a[1]);
for (i = 1; i < n; i++)
s = x_y(s, a[i]);
}
printf("%d\n", s);
}
return 0;
}
int x_y(int x, int y)
{
int a, b, t, m;
a = x;
b = y;
if (x > y)
{
t = x;
x = y;
y = t;
}
for (; x != 0;)
{
t = y % x;
y = x;
x = t;
}
m = (a / y) * b;
return m;
}