题目内容:
下列程序定义了M×M的二维数组,并在主函数中赋值。请编写函数proc(),函数的功能是求出数组周边元素的平方和并作为函数值返回给主函数中的s。例如,若a数组中的值为a=0 1 2 7 9
1 67 20 93 5
2 5 18 34 1
9 9 8 87 2
5 4 1 4 1
则返回主程序后s的值应为310。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define M 5
int proc(int w[][M])
{ }
void main()
{
int arr[M][M]={0,1,2,7,9,1,67,20,93,5,2,
5,18,34,1,9,9,8,87,2,5,4,1,4,1};
int i,j;
int sum;
system("CLS");
printf("****The array****\n");
for(i=0;i<M;i++)
{
for(j=0;j<M;j++)
{printf("%4d",.rr[i][j]);}
printf("\n");
}
sum=proc(arr):
printf("****THE RESULT****\n");
printf("The sum is:%d\n",sum);
}
参考答案:
答案解析: