#include <stdio.h> #include <iostream> using namespace std; double Variance(int * d, int n); // 方差 int main() { int a[5] = {4, 5, 7, 9, 10}; printf("%6.3f/n", Variance(a, 5)); return 0; } double Variance(int * d, int n) // 方差 { double avg, sum = 0; int i; for (i = 0; i < n; ++i) { sum += (double)d[i]; } avg = sum / n; sum = 0; for (i = 0; i < n; ++i) { sum += (d[i] - avg) * (d[i] - avg); } sum /= n; return sum; }