职业资格>计算机等级 > 二级C语言程序设计
二级C语言程序设计 - 相关题库
问答题 编号:2483645
请补充fun函数,该函数的功能是:计算N×N维矩阵元素的方差,结果由函数返回。维数在主函数中输入。例如:
  
  的计算结果是14.414。
  求方差的公式为:其中
  注意:
  请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
/**********code.c**********/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 20
/**********found**********/
double fun(__1__,int n)
{
   int i,j;
   double s=0.0;
   double f=0.0;
   double aver=0.0;
   double sd=0.0;
   for(i=0;i<N;i++)
       for(j=0;j<N;j++)
           s+=a[i][j];
   /**********found**********/
   aver=__2__;
   for(i=0;i<N;i++)
       for(j=0;j<N;j++)
           f+=(a[i][j]-aver)*(a[i][j]-aver);
   f/=(n*n);
   /**********found**********/
   sd=__3__;
   return sd;
}
void main()
{
   int a[N][N];
   int n;
   int i,j;
   double s;
   printf("*****Input the dimension of array N****** ");
   scanf("%d",&n);
   printf("*****The array***** ");
   for(i=0;i<N;i++)
   {
       for(j=0;j<N;j++)
       {
           a[i][j]=rand()P;
           while (a[i][j]==0)
               a[i][j]=rand()`;
           printf("M",a[i][j]);
       }
       printf(" ");
   }
   s=fun(a,n);
   printf("*****THE RESULT***** ");
   printf("%4.3f ",s);
}
/**********-code.c**********/

选择购买的题库