#include <iostream>
using namespace std;
int main()
{
int n;
double* p;//[100];
cout << "请输入数据的个数n";
cin >> n;
p = new double[n];
//cin >> n;
cout << "请依次输入这些数据";
double suma = 0;
for (int i = 0; i < n; i++)
{
cin >> p[i];
suma += p[i];
}
double ave = suma / n;
double* fc;// [100] ;//每一个数据与平均值的差的平方
fc = new double[n];
double sufc = 0;//fc的和
for (int i = 0; i < n; i++)
{
fc[i] = (p[i] - ave) * (p[i] - ave);
sufc += fc[i];
}
double fcc = sufc / n;
cout << "平均值为:" << ave;
cout << "\n方差*个数为:" << sufc;
cout << "\n方差为:" << fcc;
//delete p;
//delete fc;
}
c++方差计算器(大学物理实验用)(自用)
最新推荐文章于 2023-12-28 10:09:42 发布