题目内容:
下列程序定义了 M×M的二维数组.并在主函数中门动赋值。清编写函数fun(int arr[][M]).该函数的功能是使数组左下半三角元素中的值全部置成0。例如,arr数组中的值为: 1 2 3
arr= 4 5 6
7 8 9
则返回主程序后arr数组中的值应为:
0 2 3
arr= 0 0 6
0 0 0
注意:部分源程序给出如下。
清勿改动main()函数和其他函数中的任何内容,仅在
函数proc()的花括号中填人所编写的若干语句。
试题程序:
#incllid<conio.h
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define M 5
void proc(int arr[][M])
{
}
void main()
{
int arr[M][M],i,;
system("CLS"):
printf("****The array****\n");
srand((unsigned)time(NULL)):
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"):
}
}
参考答案:
答案解析: