下列程序定义了n×n的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][n]),该函数的功能是:使数组右上半三角元素中的值全部置成0。例如a数组中的值为
a=4 5 6
1 7 9
3 2 6,
则返回主程序后a数组中的值应为
0 0 0
1 0 0
3 2 0
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include
#include
#include
#define n 5
int fun (int a[][n])
{
}
main()
{
int a[n][n],i,j;
clrscr();
printf("*****the array*****n");
for(i=0;i
printf("M", a[i][j]);
}
printf("n");
}
fun(a);
printf("the resultn");
for(i=0;i
printf("n");
}
}
3. 编程题解析
int fun (int a[][n])
{
int i,j;
for(i=0;i
}
【解析】本题旨在考查控制数组中右上半三角元素的算法,也就是两个千篇一律的循环语句,希望学习者能够掌握消化。
