1、全国计算机二级 C语言上机试题 60+2015年及答案解析(总分:30.00,做题时间:90 分钟)1.给定程序中,函数 fun的功能是:将形参指针所指结构体数组中的三个元素按 num成员进行升序排列。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include typedef struct int num; char name10; PERSON; /*found*/ void fun(PERSON _1_) /*found*/ _2_ temp; if(
2、std0.numstd1.num) temp=std0; std0=std1; std1=temp; if(std0.numstd2.num) temp=std0; std0=std2; std2=temp; if(std1.numstd2.num) temp=std1; std1=std2; std2=temp; main() PERSON std = 5,“Zhanghu“,2,“WangLi“,6,“LinMin“ ; int i; /*found*/ fun(_3_); printf(“/nThe result is :/n“); for(i=0; i_2.给定程序 MODI1.C中函
3、数 fun的功能是:将 m(1m10)个字符串连接起来,组成一个新串,放入 pt所指存储区中。 例如:把 3个串:“abc“,“CD“,“EF“连接起来,结果是 “abcCDEF“。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include int fun ( char str10, int m, char *pt ) /*found*/ Int k, q, i ; for ( k = 0; k std1.num) temp=std0; std0=std1; std1=temp; if(
4、std0.numstd2.num) temp=std0; std0=std2; std2=temp; if(std1.numstd2.num) temp=std1; std1=std2; std2=temp; main() PERSON std = 5,“Zhanghu“,2,“WangLi“,6,“LinMin“ ; int i; /*found*/ fun(_3_); printf(“/nThe result is :/n“); for(i=0; i_正确答案:(第一处:由于在函数体 fun中,已经使用了 std变量,所以应填:*std。 第二处:由于temp是存放交换记录的中间变量,所以
5、应填:PERSON。 第三处:函数的调用,所以应填:std。)解析:2.给定程序 MODI1.C中函数 fun的功能是:将 m(1m10)个字符串连接起来,组成一个新串,放入 pt所指存储区中。 例如:把 3个串:“abc“,“CD“,“EF“连接起来,结果是 “abcCDEF“。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include int fun ( char str10, int m, char *pt ) /*found*/ Int k, q, i ; for ( k = 0
6、; k m; k+ ) q = strlen ( str k ); for (i=0; i /*found*/ pti = strk,i ; pt += q ; pt0 = 0 ; main( ) int m, h ; char s1010, p120 ; printf( “/nPlease enter m:“ ) ; scanf(“%d“, gets(s0) ; printf( “/nPlease enter %d string:/n“, m ) ; for ( h = 0; h m; h+ ) gets( sh) ; fun(s, m, p) ; printf( “/nThe result
7、 is : %s/n“, p) ; (分数:10.00)_正确答案:(第一处:保留字 int错写成 Int。 第二处:字符数组的字符串书写格式错误。)解析:3.程序定义了 NN的二维数组,并在主函数中自动赋值。请编写函数 fun( int aN),函数的功能是:使数组左下三角元素中的值全部置成 0 。 例如:a 数组中的值为 | 1 9 7 | | 0 9 7 | a = | 2 3 8 | 则返回主程序后 a数组中的值应为 | 0 0 8 | | 4 5 6 | | 0 0 0 | 注意: 部分源程序存在文件PROG1.C中。 请勿改动主函数 main和其它函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 给定源程序: (分数:10.00)_正确答案:(int fun ( int aN ) int i, j; for(i = 0 ; i N ; i+) for(j = 0 ; j = i; j+) aij = 0 ; )解析: