当我输入2,5,1,3时,我的方差有问题,结果是3,46但正确是2,18
double result=0;
string x1 = textBox1.Text;
string[] tab = x1.Split(',');
int n = tab.Length;
double sum = 0;
double ob = 0;
for (int i = 0; i < n; i++)
{
sum = sum + double.Parse(tab[i]);
result = sum / n;
ob = (ob + Math.Pow((double.Parse(tab[i]) - result),2)) / n;
}
textBox2.Text = ob.ToString();