全国计算机二级C语言上机试题71 2015年
(总分30, 做题时间90分钟)
1. 
给定程序中,函数fun的功能是:将形参s所指字符串中的所有数字字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数值返回。 例如,s所指字符串为:asd123fgh5##43df,处理后新字符串为:123543asdfgh##df。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include #include #include char *fun(char *s) { int i, j, k, n; char *p, *t; n=strlen(s)+1; t=(char*)malloc(n*sizeof(char)); p=(char*)malloc(n*sizeof(char)); j=0; k=0; for(i=0; i { if(isdigit(s[i])) { /**********found**********/ p[__1__]=s[i]; j++;} else { t[k]=s[i]; k++; } } /**********found**********/ for(i=0; i<__2__; i++) p[j+i]= t[i]; p[j+k]=0; /**********found**********/ return __3__; } main() { char s[80]; printf("Please input: "); scanf("%s",s); printf("\nThe result is: %s\n",fun(s)); }
2. 
给定程序MODI1.C中函数fun的功能是:首先把b所指字符串中的字符按逆序存放, 然后将a所指字符串中的字符和b所指字符串中的字符,按排列的顺序交叉合并到c所指数组中,过长的剩余字符接在c所指数组的尾部。例如,当a所指字符串中的内容为"abcdefg",b所指字符串中的内容为"1234"时,c所指数组中的内容应该为"a4b3c2d1efg";而当a所指字符串中的内容为"1234",b所指字符串中的内容为"abcdefg"时,c所指数组中的内容应该为"1g2f3e4dcba"。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include void fun( char *a, char *b, char *c ) { int i , j; char ch; i = 0; j = strlen(b)-1; /************found************/ while ( i > j ) { ch = b[i]; b[i] = b[j]; b[j] = ch; i++; j--; } while ( *a || *b ) { /************found************/ If ( *a ) { *c = *a; c++; a++; } if ( *b ) { *c = *b; c++; b++; } } *c = 0; } main() { char s1[100],s2[100],t[200]; printf("\nEnter s1 string : ");scanf("%s",s1); printf("\nEnter s2 string : ");scanf("%s",s2); fun( s1, s2, t ); printf("\nThe result is : %s\n", t ); }
3. 
函数fun的功能是:将s所指字符串中下标为偶数同时ASCII值为奇数的字符删除,s所指串中剩余的字符形成的新串放在t所指的数组中。 例如,若s所指字符串中的内容为"ABCDEFG12345",其中字符C的ASCII码值为奇数,在数组中的下标为偶数, 因此必须删除;而字符1的ASCII码值为奇数,在数组中的下标也为奇数,因此不应当删除,其它依此类推。 最后t所指的数组中的内容应是"BDF12345"。 注意: 部分源程序存在文件PROG1.C中。 请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 给定源程序: #include #include void fun(char *s, char t[]) { } main() { char s[100], t[100]; printf("\nPlease enter string S:"); scanf("%s", s); fun(s, t); printf("\nThe result is: %s\n", t); NONO(); }
答题卡