填空题
请补充main函数,该函数的功能是:从键盘出入一个字符串并保存在字符str1中,把字符串str1中下标为偶数的字符保存在字符串str2中并输出。 例如,当str1=”abcdefg”时,则str2=”aceg”。 注意:部分源程序给出如下
仅在横线上填入所编写的若干表达式或语句,请勿改动函数中的任何内容。
试题程序:
#include
charstr1[LEN],str2[LEN]; char*p1=str1,*p2=str2; inti=0,j=0;
printf(\scanf(___1___);
printf(\while(*(p1+j)) {
printf(\j++; }
for(i=0;i printf(\} 第1处填空:”%s”,str1 第2处填空:%c 第3处填空:str2 改错题 下列给定程序中,函数fun的功能是:将n个无序整数从小到大排序。 请改正程序中的错误,使其能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include inti,j,p,t; for(j=0;j /********found********/ for(i=j+1;i if(a[p]>a[i]) /********found********/ t=i; if(p!=j) { t=a[j]; a[j]=a[p]; a[p]=t; } } } putarr(intn,int*z) { inti; for(i=1;i<=n;i++,z++) { printf(\if(!(i)) printf(\} printf(\} main() { intaa[20]={9,3,0,4,1,2,5,6,8,10,7},n=11; printf(\putarr(n,aa); fun(n,aa); printf(\putarr(n,aa); } 第1处:for(i=j+1;ii 编程题 请编写函数FUN,该函数的功能是:移动字符串中的内容,移动的规则如下:把第1到第M个字符,平移到字符串的最后,把第M+1到最后的字符移到字符串的前部。 例如,字符串原有的内容为ABCDEFGHIJK,M的值为3,移动后,字符串中的内容应该是DEFGHIJKABC。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include voidfun(char*w,intm) { } main() www.Examda.CoM { chara[N]=\intm; FILE*out; printf(\puts(a); printf(\scanf(\fun(a,m); printf(\puts(a); printf(\ out=fopen(\fun(a,strlen(a)-m); fun(a,3); fprintf(out,\fclose(out); } 答案是: voidfun(char*w,intm) { charb[N]; intI,j=0; for(i=0;i b[j]=w[i]; j++; } for(i=0;i w[i]=b[j]; i++; } w[i]=’\\0’; }