请编写函数fun,函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如:二维数组中的值为: 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1

admin2015-08-23  33

问题 请编写函数fun,函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。
    例如:二维数组中的值为:
    1  3  5  7  9
    2  9  9  9  4
    6  9  9  9  8
    1  3  5  7  0
  则函数值为61。
  注意:部分源程序存在文件PROG1.C文件中。
  请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#inolude
#define M 4
#define N 5
int fun(int a[M][N])
{
}
main()
{  int aa[1][N]={{1,3,5,7,9),f 2,9,
9,9,4},{6,9,9,9,8),{1,3,5,7,0));
  int i,j,y;void NONO();
  printf ("The original data is;\n");
    for  (i=0;  i    {  for(j=0 ; j("%6d",aa[j]);
    printf("\n");
  y=fun(aa);
  printf("\nThe s1im:%d\n",y);
  printf("\n");
  NONO();
  }
  void NONO()
  {/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。  */
  int i,  j,  y,  k,  aa[M][N]  ;
  FILE*rf,*wf;
  rf=fopen("in.dat","r");
  wf=fopen("out.dat","w");
  for(k=0;k<1 0;k++)  {
    for(i=0  ;  i    for(j=0;j"%d",&aa[j]);
    y=fun(aa);
    fprintf(wf,"%d\n",y);
  )
  fclose(rf);
  fclose(wf);
}

选项

答案int tot=0, i, j; for(i=0; i
解析 进入fun函数,根据前面的分析:求周边元素的和,可以采用两个循环分别把行元素和列元素相加。但要避免把周边元素重复相加。
转载请注明原文地址:https://kaotiyun.com/show/BHDp777K
0

最新回复(0)