#include<iostream>
#include<math.h>
using namespace std;
int main() {
cout << "方差计算器" << endl;
int n;
int sum = 0, squaresum = 0;
cout << "请输入你想输入的数据个数:" << endl;
cin >> n;
int *num = new int(n);
cout << "请输入你的数据" << endl;
for(int i = 0; i < n; i++) {
cin >> num[i];
sum += num[i];
squaresum = squaresum + num[i] * num[i];
}
cout << "数据的均值为" << sum/n << endl;
cout << "数据的方差为" << squaresum/n << endl;
cout << "数据的标准差为" << sqrt(squaresum/n) << endl;
cout << "所有的数据为:" << endl;
int j = 1;
for(j = 1; 5 * j < n; j++) {//每五个数据输出一次,判断防溢出
for (int i = 0; i < 5; i++) {
cout << num[5 * j - 5] << " ";
}
cout << endl;
}
for(int i = 0;i < n + 5 - 5 * j; i++){
cout << num[i] << " ";
}
delete [] num;
}
不知为什么,好像有点问题,唔,改日再说吧