问答题
请编写函数fun,其功能是:计算并输出给定10个数的方差。
其中:
例如,给定的10个数为95.0、89.0、76.0、65.0、88.0、72.0、85.0、81.0、90.0、56.0,则输出为S=11.730729。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<math.h>
#include<stdio.h>
double fun(double x[10])
{
}
void main()
{
doubles,x[10]={95.0,89.0,76.0,65.0,88.0,72.0,85.0,81.0,90.0,56.0};
int i;
printf("\nThe original data is:\n");
for(i=0;i<10;i++)
printf("%6.1f",x[i]);
printf("\n\n");
s=fun(x);
printf("S=%f\n\n",s);
}
【参考答案】
double fun(double x[10])
{
double x1=0.0,s=0.0;......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)