Aavntva计算机二级C语言上机模拟试题10套(含解析)..docVIP

  • 7
  • 0
  • 约2.52万字
  • 约 38页
  • 2016-12-11 发布于重庆
  • 举报

Aavntva计算机二级C语言上机模拟试题10套(含解析)..doc

Aavntva计算机二级C语言上机模拟试题10套(含解析).

Time will pierce the surface or youth, will be on the beauty of the ditch dug a shallow groove ; Jane will eat rare!A born beauty, anything to escape his sickle sweep .-- Shakespeare 模拟试题(一) 1.填空题 请补充函数fun(),该函数的功能是:把从主函数中输入的字符串str2接在字符串str1的后面。 例如:str1=“How do”,str2=“ you do?”,结果输出:How do you do? 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。 试题程序: #includestdio.h #includeconio.h #define N 40 void fun(char *str1,char *str2) { int i=0; char *p1=str1; char *p2=str2; while(【1】) i++; for( ;【2】;i++) *(p1+i)=【3】; *(p1+i)=\0; } main() { char str1[N],str2[N]; clrscr(); printf(*****Input the string str1 str2*****\n); printf( \nstr1:); gets(str1); printf( \nstr2:); gets(str2); printf(**The string str1 str2**\n); puts(str1); puts(str2); fun(str1,str2); printf(*****The new string *****\n); puts(str1); } 答案及评析: 【1】*(p1+i) 【2】*p2 【3】*p2++ 【解析】填空1:变量i用来记录字符串str1的长度,当指针指到字符串str1结束标志符‘\0时,while循环结束,变量i停止累加。填空2:指针p2指向字符串str2,通过for循环将字符串str2接在str1后面,循环结束的条件是指针p2所指的字符是字符串结束标志符‘\0。填空3:指针p2最初指向字符串str2的首字符,通过自加1,使指针p2依次向后移动,指向str2的各个字符,实现将字符串str2接在str1后面的功能。 2. 改错题 下列给定程序中,函数fun()的作用是:将字符串tt中的小写字母都改为对应的大写字母,其他字符不变。例如,若输入edS,dAd,则输出EDS,DAD。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include stdio.h #include string.h #include conio.h /**********************found***********************/ char fun(char tt[]) { int i; for(i=0;tt[i];i++){ /**********************found***********************/if((tt[i]=A)(tt[i]= Z))tt[i]-=32;} return(tt); } main() { int i; char tt[81]; clrscr(); printf(\nPlease enter a string: ); gets(tt); printf(\nThe result string is: \n%s,fun(tt)); } 答案及评析: (1)错误:char fun(char tt[]) 正确:char *fun(char tt[]) (2)错误:if((tt[i]=A)(tt[i]= Z)) 正确:if((tt[i]=a)(tt[i]= z)) 【解析】错误1:函数的返回值是字符串的首地址,是指针类型,所以在函数名前要加*号。 错误2:题目要求将小写字母改为大写字母,所以if语句的判断条件是小写字母。 3. 编程题 请编写函数fun(),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p到n-1(p≤n-1)的数组元素平移到数组的前面。 例如,一维数组中的原始内容为1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,p的值为6

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档