问答题

下列程序定义了M×M的二维数组,并在主函数中赋值。请编写函数proc(),函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如,若a数组中的值为:
a=0 1 2 3 4
5 9 7 4 5
4 3 8 3 6
3 5 6 8 7
2 1 0 9 8
则返回主程序后,S的值为3.750000。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define M 5
double proc(int w[][M])


void main()

int a[M][M]=0, 1, 2, 3, 4, 5, 9, 7, 4, 5, 4, 3, 8, 3, 6, 3, 5, 6, 8, 7, 2, 1, 0, 9, 8;
int i, j;
double s;
system("CLS");
printf("*****The array*****\n");
for(i=0; i<M; i++)
for(j=0; j<M; j++)
printf("%4d", a[i][j]);
printf("\n");

s=proc(a);
printf("*****THE RESULT*****\n");
printf("The sum is: %lf\n", s);

【参考答案】

double proc(int w[][N])
{
int i, j, k=0;
dou......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)