题目内容:
下列程序定义了M;M的二维数组,并在主函数中自动赋值。请编写函数proc(int arrE3[-M3),该函数的功能是使数组右上半三角元素中的值全部置成0。例如a数组中的值为: arr=1 2 3
4 5 6
7 8 9,
则返回主程序后a数组中的值应为:
arr=0 0 0
4 0 0
7 8 0
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<coni0.h>
#include<stdi0.h>
#include<stdlib.h>
#include<time.h>
#define M 5
void proc(int arr[][M])
{ }
void main()
{
int arr[M][M],i,J;
srand((unsigned)time(NULL)):
system("CLS"):
printf("****The array****\n");
for(i=0;i<M;i++)
//产生一个随机的5*5矩阵
{
for(j=0;j<M;j++)
{
arr[i][j]=rand()%10;
printf("%4d",arr[i][j]);
}
printf("\n");
}
proc(arr);
printf("THE RESULT\n"):
for(i=0;i<M;i++)
{
for(j=0;j<M;j++)
printf("%4d",arr[i][j]):
printf("\n");
}
}
参考答案:
答案解析: