C语言中求大于M10个最大素数,全国计算机二级C语言上机题库—南开100题

41528d3028836879cd698677c3999917.gif全国计算机二级C语言上机题库—南开100题

全国计算机二级C语言上机题库—南开100题 第一套 1.请补充fun函数,fun函数的功能是求m的阶乘。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h long fun(int m) {【答案及难度指数】★★ (1)m1 (2)m-1 (3)1 2.下列给定程序的功能是:读入一个整数n(2≤n≤5000),打印它的所有为素数的因子。例如,若输入整数1234,则应输出:2、617。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ Prime(int m); { int j,p; p=1; /*******error*********/ for(j=2;jm;j++) if!(m%j) { p=0; break; } return(p); } main() { int i,n; printf(\nplease enter an integer number between 2 and 5000:); scanf(%d,n); printf(\n\nThe prime factor(s) of %d is(are):,n); for(i=2;in;i++) if((!(n%i)) (Prime(i))) printf( %4d,,i); printf(\n); } 【答案及难度指数】★★ (1)Prime(int m) (2)if(!(m%j)) 3.数组point中存放着m个人的成绩,请编写函数fun,它的功能是:返回高于平均分的人数,并将高于平均分的分数放在high所指的数组中。 例如,当point数组中的数据为50、60、65、70、75、80、88、90、95时,函数返回的人数应该是5,high中的数据应为75、80、88、90、95。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h int fun(int point[],int n,int high[]) { } main() { int j,m,high[9]; int point[9]={50,60,65,70,75,80, 88,90,95}; FILE *out; m=fun(point,9,high); printf(\nHigh the average point are :); out=(outfile.dat,w); for(j=0;jm;j++) { printf(%d ,high[j]); fprintf(out,%d\n0,high[j]); } fclose(out); } 【答案及难度指数】★★ int j,k=0,average=0; for(j=0;jn;j++) average+=point[j]; //统计总分数 average/=n;//求平均分 for(j=0;jn;j++) if(point[j]average) //逐个判断每个分数是否大于平均分 { high[k]=point[j]; //将高于平均分的人放入high数组 k++; //统计大于平均分的人数 } return k; } 第二 套 1.请补充fun函数,该函数的功能是:判断一个年份是否为闰年。 例如,2007年不是闰年,2008是闰年。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h int fun(int n) { int flag=0; if(n%4==0) if(___1___) flag=1; if(___2___) flag=1; return ___3___; } main() 【答案及难度指数】★ (1)n%100!=0 (2)n%400==0 (3)flag 2.下列给定程序中,fun函数的功能是:根据形参n,计算如下公式的值。 s=1+1111+++L+234n 例如,若输入5,则应输出2.28333。 请修改程序中的错误或在横线处填上适当的内容并把横线删除,使它能计算出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h double fun(int n) { double s=1.0; int i; /******error**********/ for(i=2;i=n;i++) s+=1.0/k; /******error**********/ ___填 空___ } main() { int n; printf(\nplease enter 1 integer numbers:\n); scanf(%d,n); printf(\n\nthe result is %lf\n,fun(n)); } 【答案及难度指数】★★ (1)s+=1.0/i; (2)return s; } 3.请编写函数fun,它的功能是:求出1到500之内能被7或11整除,但不能同时被7和11整除的所有整数,并将它们放在b所指的数组中,通过m返回这些数的个数。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int *b,int *m) { } main() { int a[500],m,i; FILE *out; fun(a,m); out=(outfile.dat,w); for(i=0;im;i++) if((i+1)%10==0) { printf(%5d\n,a[i]); fprintf(out,d\n,a[i]); } else { printf(%5d,,a[i]); fprintf(out,%d,,a[i]); } fclose(out); } int n; printf(\nplease enter 1 integer numbers:\n); scanf(%d,n); printf(\n\nthe result is %lf\n,fun(n)); } 【答案及难度指数】★★★ int j,k=0; for(j=2;j500;j++) //循环条件 if((j%7==0||j%11==0)j%77!=0) //判断是否符合题干要求 b[k++]=j; //将结果放入数组b *m=k; //将累加器值赋值给m 第三套 1.函数fun的功能是:从三个形参x、y、z中找出中间的那个数,作为函数值返回。 例如,当x=121,y=456,z=333时,中间的数为333。 请勿改动主函数main与其他函数中的任何%d\n,mid); } 【答案及难度指数】★ (1)a (2)a (3)b 2.下列给定程序中,函数fun和quest的功能是:用二分法求方程2x3-4x2+3x-6=0的一个根,并要求绝对误差不超过0.001。例如,若给m输入-50,给n输入30,则函数求得的一个根值为2.000。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include math.h double quest(double x) { return (2*x*x*x-4*x*x+3*x-6); } double fun(double m,double n) { /********error********/ int r; r=(m+n)/2; /********error********/ while(fabs(n-m)0.001) { if(quest(r)*quest(n)0) m=r; else n=r; r=(m+n)/2; } return r; } main() { double m,n,result; printf(Please m n : \n); scanf(%lf%lf,m,n); result=fun(m,n); printf(result=%6.3f\n,result); } 【答案及难度指数】★★ (1)double r; (2)while(fabs(n-m)0.001) 3.请编写函数void fun(int y,int b[],int*m),它的功能是:求出能整除y且是奇数的各整数,并按从小到大的顺序放在b所指的数组中,这些除数的个数通过形参m返回。 例如,若y中的值为90,则有4个数符合要求,它们是1、3、5、9、15、45。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int y,int b[],int *m) { } main() { int y,a[500],m,j; FILE *out; printf(\nPlease an integer number:\n); scanf(%d,y); fun(y,a,m); for(j=0;jm;j++) printf(%d ,a[j]); printf(\n); fun(730,a,m); out=(outfile.dat,w); for(j=0;jm;j++) fprintf(out,%d\n,a[j]); fclose(out); } 【答案及难度指数】★★★ int j=1,i=0,k=0,*s=b; for(j=0;j=y;j++) if(j%2!=0) //判断j是否是奇数 { s[i]=j;//将小于y的奇数存入数组s i++; //累加小于y的奇数个数 } for(j=0;ji;j++) if(y%s[j]==0) //判断y是否被s[j]整除 { b[k]=s[j];//将符合条件的结果存入数组b k++; //累加符合条件的结果个数 } *m=k; 第四套 1. 请补充函数fun(char *t),该函数的功能是把字符串中的内容逆置。 例如,字符串中原有的字符串为ABCDE,则调用该函数后,串中的内容为EDCBA。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include string.h # include conio.h # include stdio.h # define M 60 void fun(char *t) { int j,m=strlen(t)-1; char s; for(j=0;jm;j++,___1___) { s=t[j]; ___2___; ___3___; } } main() { char b[M]; printf( a string:); gets(b); printf(The original string is:); puts(b); fun(b); printf(\n); printf(The reversal string :); puts(b); } 【答案及难度指数】★ (1)m-- (2)t[j]=t[m] (3)t[m]=s 2下列给定程序中,函数fun的功能是:判断字符ch是否与s所指串中的某个字符相同,若相同,则什么也不做;若不同,则将其插在串的最后。 请修改程序中的错误,使它能得出正确的操作。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h /*******error*********/ void fun(char s,char c) { while(*s *s!=c) s++; /*******error*********/ if(*s==‘c’) { s[0]=c; /*******error*********/ s[1]=‘0’; } } main() { char str[81],ch; printf(\n Please enter a string:\n); gets(str); printf(\n Please enter the character to search:); ch=getchar(); fun(str,ch); printf(\nThe result is %s\n,str); } 【答案及难度指数】★★ (1)void fun(char *s,char c) (2)if(*s==‘\0’) (3)s[1]=‘\0’; 请编写函数fun,函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 3.例如,若二维数组中的值为: 3 5 7 9 9 9 9 4 9 9 9 8 则函数值为72。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # define M 3 # define N 4 int fun(int b[M][N]) { } main() { int a[M][N]={{3,5,7,9},{9,9,9,4}, {9,9,9,8}}; int i,j,sum; FILE *out; printf(The original data is : \n); for(i=0;iM;i++) { for(j=0;jN;j++) printf(%6d,a[i][j]); printf(\n); } sum=fun(a); printf(\nThe sum: %d\n,sum); printf(\n); out=(outfile.dat,w); fprintf(out,%d,sum); fclose(out); } 【答案及难度指数】★★★ int i,j,s=0; for(j=0;jN;j++) //统计行元素 { s+=b[0][j]; s+=b[M-1][j]; } for(i=1;i=M-2;i++) //统计列元素 { s+=b[i][0]; s+=b[i][N-1]; } return s; 第五套 1.请补充main函数,该函数的功能是:从键盘输入一个长整数,如果这个数是负数,则取它的绝对值,并显示出来。例如,输入:-666,结果为:666。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include conio.h main() { long int a; printf(Enter the data:\n); scanf(___1___); printf(The origial data is %ld\n,a); if(a0) ___2___; printf(\n); printf(___3___); } 【答案及难度指数】★ (1)%ld,a (2)a=-a (3)%ld,a 2.下列给定程序中函数fun的功能是:求出在字符串中最后一次出现的子字符串的地址,通过函数值返回,在主函数中输出从此地址开始的字符串;若未找到,则函数值为NULL。 例如,当字符串中的内容为abcdabfabcdx,t中的内容为ab时,输出结果应是:abcdx。当字符串中的内容为abcdabfabcdx,t中的内容为abd时,则程序输出未找到信息not found!。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h char *fun(char *str,char *t) { char *p,*r,*s; /********error********/ s=NuLL; while(*str) { p=str; r=t; while(*r) /*******error*********/ if(r==p) { r++; p++; } else { break; } if(*r==‘\0’) s=str; str++; } return s; } main() { char str[100],t[100],*p; printf(\nplease enter string s:); scanf(%s,str); printf(\nplease enter substring t:); scanf(%s,t); p=fun(str,t); if(p) printf(\nthe result is:%s\n,p); else printf(\nnot found!\n); } 【答案及难度指数】★★ (1)s=NULL; (2)if(*r==*p) 3.编写函数int fun(int mm,int b[MAX]),该函数的功能是求出小于或等于mm的所有素数,并放在b数组中,该函数返回所求出的素数的个数。 请勿改动主函数main与其他函数中的任何 //判断i是否是素数 break; //若i能被j整除,则i为非素数 else continue; //否则继续循环判断 if(j=i) //若是素数,将其存入b { b[k]=i; k++; //累加素数个数 } } return k++; 第六套 1.请补充函数fun,它的功能是:计算并输出m(包括m)以 (n=1) fun(n)= fun(n-1)+2 (n1) 例如,当给n输入6时,函数值为20。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h /********error********/ int fun(n) { int m; /********error********/ if(n=1) m=10; else m=fun(n-1)+2; return (m); } main() { int n; printf(Enter n: ); scanf(%d,n); printf(The result:%d\n\n,fun(n)); } 【答案及难度指数】★★ (1)int fun(int n) (2)if(n==1) 3.请编写函数fun,对长度为7个字符的字符串,除首、尾字符外,将其余5个字符按ASCII码降序排列。 例如,原来的字符串为Justabc,则排序后输出为Jutsbac。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include ctype.h # include conio.h # include string.h void fun(char *str,int n) { } main() { char str[10]; FILE *out; printf( string with seven characters:); gets(str); fun(str,7); printf(\n%s,str); out=(outfile.dat,w); strcpy(str,Justsdf); fprintf(out,%s,str); fclose(out); } 【答案及难度指数】★★★ char t; int i,j; for(i=1;in-2;i++) //对n个元素进行循环选择 for(j=i+1;jn-1;j++) if(str[i]str[j]) //将str[i]设为最大值,和剩下的j~n-1进行比较 { t=str[i]; str[i]=str[j]; str[j]=t; } 第七套 请补充fun函数,该函数的功能是把从键盘输入的3个整数按从大到小输出。 例如,输入11 65 13,结果输出65 13 11。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include conio.h main() { int a,b,c,t; printf( a,b,c\n); scanf(%d%d%d,a,b,c); if(___1___) { t=a; a=b; b=t; } if(___2___) { t=c; c=a; a=t; } if(___3___) { t=b; b=c; c=t; } printf(The result\n); printf(from big to small: %d %d %d\n,a,b,c); } 【答案及难度指数】★ (1)ab (2)ac (3)bc 下列给定程序中,计算如下公式的值: t=1-111--L-2´23´3m´m 函数fun的功能是:根据整型形参m的值,计算上面公式。例如,若m的值为10,则应输出:0.450232。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h double fun(int m) { double c=1.0; int k; /*******error*********/ for(k=2;km;k++) /*******error*********/ c-=1/(k*k); return(c); } main() { int para=10; printf(\nThe result is %1f\n,fun(para)); } 【答案及难度指数】★★ (1)for(k=2;k=m;k++) (2)c-=1.0/(k*k); 3.请编写一个函数fun,它的功能是:将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数)。 例如,若输入字符串:-999,则函数把它转换为整数值:-999。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h long fun(char *str) { } main() { char s[10]; long n; FILE *out; char *t[]={123,789,7102,-4356}; printf(Enter a string:\n); gets(s); n=fun(s); printf(%ld\n,n); out=(outfile.dat,w); for(n=0;n4;n++) fprintf(out,%ld\n,fun(t[n])); fclose(out); } 【答案及难度指数】★★★ long s=0,t; int i=0,j,n=strlen(str),k,s1; //求得字符串长度n if(str[0]==‘-’) i++; for(j=i;j=n-1;j++) { t=str[j]-’0’;//把字符变成数值 s1=10; for(k=j;kn-1;k++) t*=s1; //把t中原来的数值增加10倍,即向左移动一位 s+=t; //把转换后的数值t加在个位 } if(str[0]==‘-’) //判断数字字符是否为负数 return-s; //负数返回-s else return s; //正数返回s 第八套 1.给定程序的功能是分别统计字符串中大写字母和小写字母的个数。 例如,给字符串str输入:sfd34ddfoFFDEsd23sdf,则输出结果应为:cap=4,min=13 请勿改动函数中的其他内容,仅在横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h void fun(char *str,int *x,int *y) { while(*str) { if(*str=‘A’ *str=‘Z’) ___1___; if(*str=‘a’ *str=‘z’) ___2___; str++; } } main() { char str[100]; int cap=0,min=0; printf(\nPlease a string to count : ); gets(str); fun(str,cap,min); printf(\n cap=%d min=%d\n,___3___); } 【答案及难度指数】★★ (1)(*x)++ (2)(*y)++ (3)cap,min 2.下列给定程序中,函数fun的功能是:根据以下公式求π值,并作为函数值返回。 π11231234=1++´´+´´´+L233573579 例如,给指定精度的变量eps输入0.0005时,应当输出Pi=3.140578。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include math.h # include stdio.h double fun(double eps) { double r,temp; int m=1; r=0.0; /*******error*********/ temp=0; /********error********/ while(temp=eps) { r+=temp; temp=(temp*m)/(2*m+1); m++; } return (r*2); } main() { double x; printf(\nPlease enter a precision: ); scanf(%lf,x); printf(\neps=%lf,Pi=%lf\n\n,x,fun(x)); } 【答案及难度指数】★★ (1)temp=1.0; (2)while(temp=eps) 3.请编写一个函数fun,它的功能是:比较两个字符串的长度(不得调用C语言提供的求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相同,则返回第一个字符串。 例如,输入beijing和shanghai两个字符串,函数将返回shanghai。 请勿改动主函数main与其他函数中的任何//计算串str的长度n,其中s1为临时指针 { n++; s1++; } while(*t1) //计算串t的长度m,其中t1为临时指针 { m++; t1++; } if(n=m) //比较m和n的值,设置p指向较大的指针 p=str; else p=t; return p; 第九套 1.给定程序的功能是求1/4的圆周长,函数通过形参得到圆的直径,函数返回1/4的圆周长(圆周长公式为:L=πd,在程序中定义的变量名要与公式的变量相同)。 例如,输入圆的直径值:19.527,输出为:15.336457。 请勿改动主函数main与其他函数中的任何内容,仅在横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h double fun(double d) { return 3.14159*___1___/4.0; } main() { double z; printf( the d of the round : ); scanf(%lf,___2___); printf( L=%lf\n ,fun(___3___)); } 【答案及难度指数】★ (1)d (2)z (3)z 2.下列给定程序中函数fun的功能是:计算正整数m的各位上的数字之积。例如,若输入202,则输出应该是0。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include conio.h long fun(long n) { /****error******/ long r; do { r*=n%10; /****error******/ n\=10; } while(n); return (r); } main() { long m; printf(\nplease enter a number:); scanf(%ld,m); printf(\n%ld\n,fun(m)); } 【答案及难度指数】★★ (1)long r=1; (2)n/=10; 3.请编写一个函数fun,它的功能是:求出1到m之内(含m)能被7或11整除的所有整数放在数组b中,通过n返回这些数的个数。 例如,若传送给m的值为20,则程序输出7 11 14。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # define N 100 void fun(int m,int *b,int *n) { } main() { int a[N],n,i; FILE *out; fun(20,a,n); for(i=0;in;i++) if((i+1)%20==0) printf(%4d\n,a[i]); else printf(%4d,a[i]); printf(\n); out=(outfile.dat,w); fun(100,a,n); for(i=0;in;i++) if((i+1)%10==0) fprintf(out,%4d\n,a[i]); else fprintf(out,%4d,a[i]); fclose(out); } 【答案及难度指数】★★★ int i,j=0;*n=0; for(i=1;i=m;i++) if(i%7==0||i%11==0) { b[j]=i; j++; } *n=j; 第10套 函数fun的功能是:统计长整数test的各位上出现数字5、6、7的次数,并通过外部(全局)变量sum5、sum6、sum7返回主函数。 例如,当test=89431676时,结果应该为:sum5=0 sum6=2 sum7=1。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h int sum5,sum6,sum7; void fun(long test) { sum5=sum6=sum7=0; while(test) { switch(___1___) { case 5: sum5++; ___2___; case 6: sum6++; ___3___; case 7: sum7++; } test /=10; } } main() { long test=89431676L; fun(test); printf(\nThe count result :\n); printf(test=%ld sum5=%d sum6=%d sum7=%d\n,test,sum5,sum6,sum7); } 【答案及难度指数】★★ (1)test%10 (2)break (3)break 2. 下列给定程序中,函数fun的功能是:将字符串str中的小写字母都改为对应的大写字母,其他字符不变。例如,若输入asAS,则输出ASAS。 请修改程序中的错误,使它能统计出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h char *fun(char str[]) { int i; /********error********/ for(i=0;str[i];i++) if((str[i]=‘a’) || (str[i]=‘z’)) /*******error*********/ str[i]+=32; return (str); } main() { char str[81]; printf(\nPlease enter a string:); gets(str); printf(\nThe result string is :\n%s,fun(str)); } 【答案及难度指数】★★ (1)if((str[i]=‘a’) (str[i]=‘z’)) (2)str[i]-=32; 3.请编写一个函数fun,它的功能是:找出一维整型数组元素中最小的值和它所在的下标,最小的值和它所在的下标通过形参传回。数组元素中的值已在主函数中赋予。 主函数中a是数组名,n是a中的数据个数,min存放最小值,flag存放最小值所在元素的下标。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdlib.h # include stdio.h # include string.h void fun(int b[],int n,int *min,int *d) { } main() { int i,a[20],min,flag,n=10; FILE *out; for(i=0;in;i++) { a[i]=rand()%50; printf(%4d,a[i]) ; } printf(\n); fun(a,n,min,flag); printf(min=%5d,Index=%4d\n,min, flag); out=(outfile.dat,w); memcpy(a,3.141592653589793238462 643383279,32); fun(a,8,min,flag); fprintf(out,min=%5d,Index=%4d, min,flag); fclose(out); } 【答案及难度指数】★★★ int i; *min=b[0]; //设置最小值初值 *d=0; //设置最小值标志位初值 for(i=0;in;i++) if(b[i]*min) //在循环中,对每一个元素与最小值标志值进行比较 { *min=b[i]; //对最小值进行赋值 *d=i; //对最小值标志位进行赋值 } 第十一 套 1. 请补充main函数,该函数的功能是:从键盘输入一组整数,使用条件表达式找出最大的整数。当输入的整数为-1时结束。 例如,输入96 121 23 343 232 54 89 365 89 -1时,最大的数为365。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # define NUM 100 main() { int n[NUM]; int i=-1; int MAX=-1; printf(\nInsert integer with the ‘-1’ as end: \n); do { i++; printf(n[%d]=,i); scanf(%d,___1___); MAX=___2___n[i] : MAX; } while(___3___); printf(The MAX=%d\n,MAX); } 【答案及难度指数】★★ (1)n[i] (2)MAXn[i]? (3)n[i]!=-1 2.下列给定程序中,函数fun的功能是:将一个由八进制数字字符组成的字符串转换为与其数值相等的十进制整数。规定输入的字符串最多只能包含5位八进制数字。例如,若输入11111,则输出将是4681。 请修改程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include stdlib.h # include string.h int fun(char *s) { int n; /********error********/ n=*s-’o’; s++; /********error********/ while(*s!=0) { n=n*7+*p-’o’ s++; } return n; } main() { char str[6]; int i; int n; printf(Enter a string (octal digits): ); gets(str); if(strlen(str)5) { printf(Error:string too longer!\n\n); exit(0); } for(i=0;str[i];i++) if(str[i]’0’ || str[i]’7’) { printf(Error: %c not is octal digits!\n\n,str[i]); exit(0); } printf(The original string: ); puts(str); n=fun(str); printf(\n%s is convered to intege number: %d\n\n,str,n); } 【答案及难度指数】★ (1)n=*s-’0’; (2)n=n*8+*s-’0’; 3.下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun,函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的r。 例如,若c数组中的值为: 97 c=452 383 则返回主程序后r的值应为4.625000。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # include stdlib.h # define N 3 double fun(int b[][N]) { } main() { int c[N][N]={1,9,7,4,5,2,3,8,3}; int i,j; FILE *out; double r; printf(**********\n); for(i=0;iN;i++) { for(j=0;jN;j++) { printf(%4d,c[i][j]); } printf(\n); } r=fun(c); printf(THE RESULT\n); printf(The r is %lf\n,r); out=(outfile.dat,w); fprintf(out,%lf,r); fclose(out); } 【答案及难度指数】★★★ int i,j,k=0; double r=0.0; for(j=0;jN;j++) //统计第一行进行统计 { r+=b[0][j]; k++; } for(j=0;jN;j++) //对第n-1行进行统计 { r+=b[N-1][j]; k++; } for(i=1;i=N-2;i++) //对第一列进行统计 { r+=b[i][0]; k++; } for(i=1;i=N-2;i++) //对第n-1列进行统计 { r+=b[i][N-1]; k++; } return r/=k; //求平均数 第十二套 1.请补充fun函数,该函数的功能是将字符串str中的小写字母都改为对应的大写字母,其他字符不变。 例如,若输入Welcome!,则输出WELCOME!。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # include conio.h char *fun(char str[]) { int j; for(j=0;str[j];j++) { if((str[j]=‘a’)(___1___)) str[j]-=___2___; } return (___3___); } main() { char str[100]; printf(\nPlease enter a string: ); gets(str); printf(\nThe result string is: \n%s,fun(str)); } 【答案及难度指数】★★ (1)str[j]=‘z’ (2)32 (3)str 2.下列给定程序中,函数fun的功能是:计算并输出n以内最大的10个能被11或19整除的自然数之和。n的值由主函数传入,若n的值为300,则函数值为2646。 请修改程序中的错误或在横线处填上适当的内容并把横线删除,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h int fun(int n) { int m=0,mix=0; while((n=2) (mix10)) { /*******error*********/ if((n%11=0) || (n%19=0)) { m=m+n; mix++; } n--; } return m; /********error********/ ___填 空___ main() { printf(%d\n,fun(300)); } 【答案及难度指数】★ (1)if((n%11==0) || (n%19==0)) (2)} 3.请编写函数fun,其功能是:将str所指字符串中除了下标为偶数、同时ASCII值也为偶数的字符外,其余的全都删除;串中剩余字符所形成的一个新串放在s所指的数组中。 例如,若str所指字符串中的 //取字符串str长度 for(i=0;in;i++) if(i%2==0str[i]%2==0) //判断字符i是否符合条件 { s[j]=str[i]; //将偶数下标及偶数ASCII码的字符放入新串 j++; //新串长度加1 } s[j]=‘\0’; //新串添加尾符 第十三套 1.请补充fun函数,该函数的功能是:依次取出字符串中所有大写字母,形成新的字符串,并取代原字符串。例如,输入sdfASDsd,则输出ASD。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h void fun(char *s) { int j=0; char *p=s; while(___1___) { if(*p=‘A’ *p=‘Z’) { s[j]=*p; ___2___; } p++; } s[j]=___3___; } main() { char str[100]; printf(\nPlease a string :); gets(str); printf(\n\nThe original string is : %s\n,str); fun(str); printf(\n\nThe string of changing is : %s\n,str); } 【答案及难度指数】★★ (1)*p (2)j++ 2.下列给定程序中,函数fun的功能是:先从键盘上输入一个3行3列矩阵的各个元素的值,然后输出主对角线元素之和。 请修改函数fun中的错误或在横线处填上适当的内容并把横线删除,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h void fun() { int aa[3][3],sum; int i,j; /********error********/ ___填 空___; for(i=0;i3;i++) for(j=0;j3;j++) /*******error*********/ scanf(%d,,aa[i][j]); for(i=0;i3;i++) sum=sum+aa[i][i]; printf(sum=%d\n,sum); } main() { fun(); } (3)’\0’ 【答案及难度指数】★ (1)sum=0 (2)scanf(%d,,aa[i][j]); 3.请编写一个函数void fun(int *s,int t,int *result),用来求出数组的最小元素在数组中的下标,并存放在result所指的存储单元中。 例如,输入如下整数: 564,165,567,121,948,324,329,454,5345,783,434,124,561,985,555 则输出结果为:3,121。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int *s,int t,int *result) { } main() { int store[15]={564,165,567,121,948, 324,329,454,5345,783,434,124,561,985,555},result; FILE *out; fun(store,10,result); printf(%d,%d\n,result,store [result]); out=(outfile.dat,w); fprintf(out,%d\n%d,result,store [result]); fclose(out); } 【答案及难度指数】★★★ int temp ,min; min=s[0]; //将数组s的第一个元素s[0]赋于min for(temp=0;tempt;temp++) if(s[temp]min) //判断min与数组每个元素的大小 { min=s[temp]; //将小于min的数组元素赋值给min *result=temp;//将结果下标赋值给指针result } 第十四套 1.给定程序的功能是判断字符串s中的某个字符是否与字符ch相同,若相同什么也不做,若不同则插在字符串的最后。例如,输入test,如果输入e,输出结果不变。但如果输入a,结果testa。 请勿改动主函数main与其他函数中的任何内容,仅在横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h void fun(char *s,char ch) { while(*s *s!=ch) s++; if(*s ___1___ ch) { s[0]=ch; ___2___=0; } } main() { char str[81],c; printf(\nPlease a string:\n); gets(str); printf(\n Please enter the character to search : ); c=getchar(); fun(___3___); printf(\nThe result is %s\n,str); } 【答案及难度指数】★★ (1)!= (2)s[1] (3)str,c 2.下列给定程序中,函数fun的功能是:按顺序给t所指数组中的元素赋予从2开始的偶数,然后再按顺序对每5个元素求一个平均值,并将这些值依次存放在r所指的数组中。若t所指数组中元素的个数不是5的倍数,多余部分忽略不计。例如,t所指数组有14个元素,则只对前10个元素进行处理,不对最后的4个元素求平均值。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # define NUM 20 int fun(double *t,double *r) { int j,i; double sum; for(j=2,i=0;iNUM;i++) { t[i]=j; j+=2; } sum=0.0; for(j=0,i=0;iNUM;i++) { sum+=t[i]; /********error********/ if(i+1%5==0) { r[j]=sum/5; sum=0; j++; } } return j; } main() { double a[NUM],b[NUM/5]; int i,j; j=fun(a,b); printf(The original data:\n); for(i=0;iNUM;i++) { if(i%5==0) printf(\n); printf(%4.0f,a[i]); } printf(\n\nThe result :\n); for(i=0;ij;i++) printf(%6.2f ,b[i]); printf(\n\n); } 【答案及难度指数】★ if((i+1)%5==0) 3.请编写一个函数void fun(int x,int sum,int select[]),该函数的功能是:将大于整数x且紧靠x的sum个素数存入select所指的数组中。 例如,若输入:121 8,则应输出:127 131 137 139 149 151 157 163。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int x,int sum,int select[]) { } main() { int x,y,a[500]; FILE *out; printf(\n two numbers:); scanf(%d,%d,x,y); fun(x,y,a); for(x=0;xy;x++) printf(%d ,a[x]); printf(\n); fun(121,10,a); out=(outfile.dat,w); for(x=0;x10;x++) fprintf(out,%d\n,a[x]); fclose(out); } 【答案及难度指数】★★★ int r=0,temp,p,sign=1; for(temp=x+1;tempx*x;temp++) //从temp开始循环,判断紧靠temp的整数 { for(p=2;ptemp;p++) { if(temp%p!=0) //判断temp是否为素数 sign=1;//若是素数,标志设为1 else { sign=0; //若不是素数,标志设为0 break; } } if(sign==1p=temp) { if(sum=0) //判断已有的素数个数是否已经满足sum个 { select[r++]=temp;//将素数temp存入数组select sum--;//将题目中要求的素数个数减1 } else break; } 第十五套 1.给定程序的功能是计算score中n个人的平均成绩aver,将高于aver的成绩放在high中,通过函数名返回人数。例如,score={88,75,50,60,80,90},n=6时,函数返回的人数应该是4,high={88,75,80,90}。 请勿改动主函数main与其他函数中的任何内容,仅在横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h int fun(int score[],int m,int high[]) { int i,j=0; float aver=0.0; for(i=0;im;i++) aver+=score[i]; aver /=(float)m; for(i=0;im;i++) if(score[i]aver) high[j++]=___1___; return j; } main() { int i,n,high[6]; int score[6]={88,75,50,60,80,90}; n=fun(score,6,___2___); printf(\nThe high of average score are: ); for(i=0;in;i++) printf(%d ,___3___); } 【答案及难度指数】★★ (1)score[i] (2)high (3)high[i] 2.已知一个数列从第0项开始的前三项分别为0、0、1,以后的各项都是其相邻的前三项之和。下列给定程序中,函数fun的功能是:计算并输出该数列前n项的平方根之和sum。n的值通过形参传入。例如,当n=4时,程序输出结果应为2.000000。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include math.h /******error**********/ fun(int n) { double sum,a0,a1,a2,a; int i; sum=1.0; if(n=2) sum=0.0; a0=0.0; a1=0.0; a2=1.0; for(i=4;i=n;i++) { a=a0+a1+a2; sum+=sqrt(a); a0=a1; a1=a2; a2=a; } /******error**********/ return sum } main() { int n; printf( N=); scanf(%d,n); printf(%lf\n,fun(n)); } 【答案及难度指数】★ (1)double fun(int n) (2)return sum; 3.学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组score中,请编写函数fun,它的功能是把分数最低的学生数据放在low所指的数组中,注意:分数最低的学生可能不只一个,函数返回分数最低的学生的人数。 请勿改动主函数main与其他函数中的任何SCORE; int fun(SCORE *a,SCORE *b) { } main () { SCORE stu[M]={{GA03,76},{GA04, 85},{GA01,91},{GA08,64},{GA06,87},{GA014,91},{GA011,77},{GA017,64},{GA018,64},{GA016,72}}; SCORE low[M]; int i,n; FILE *out; n=fun(stu,low); printf(The %d lowest score :\n,n); for(i=0;in;i++) printf(%s %4d\n,low[i].num, low[i].s); printf(\n); out= (outfile.dat,w); fprintf(out,%d\n,n); for(i=0;in;i++) fprintf(out,%4d\n,low[i].s); fclose (out); } 【答案及难度指数】★★★ int i,j=0,n=0,min; //最低分数人数初始值为0 min=a[0].s; //初始设定最小值为第一个学生的分数 for(i=0;iM;i++) //进入循环求得最小值 if(a[i].smin) min=a[i].s; for(i=0;iM;i++) //进入循环将所有成绩与最小值进行比较 if(a[i].s==min) { *(b+j)=a[i]; //如果等于最小值,存入数组b j++; //下标加1 n++; //最低分数学生加1 } return n; //返回最低成绩人数 第16 套 1.请补充main函数,该函数的功能是:从键盘输入3个整数,然后找出最小的数并输出。 例如,输入78,53,123,则输出为53。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include conio.h main() { int x,y,z,min; printf(\n three numbers:\n); scanf(%d,%d,%d,x,y,z); printf(The three numbers are:%d, %d,%d\n,x,y,z); if(xy) ___1___; else ___2___; if(minz) ___3___; printf(min=%d\n,min); } 【答案及难度指数】★ (1)min=x (2)min=y (3)min=z 2.下列给定程序中,fun函数的功能是:分别统计字符串中小写字母和大写字母的个数。例如,给字符串t输入:adfsFFssefSCGSDew,则应输出结果:big=7,small=10。 请修改程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ void fun(char *t,int c,int d) { while(*t) { /*******error*********/ if(*t=‘A’ *t=‘Z’) *c++; /*******error*********/ if(*t=‘a’ *t=‘z’) *d++; t++; } } main() { char t[200]; int big=0,small=0; printf(\nPlease a string : ); gets(t); fun(t,big,small); printf(\n big=%d small=%d\n,big,small); } 【答案及难度指数】★★ (1)void fun(char *t,int *c,int *d) (2)(*c)++; (3)(*d)++; 3.请编一个函数void fun(int a[M][N],int b[N]),c指向一个M行N列的二维数组,求出二维数组每列中最大元素,并依次放入b所指一维数组中。二维数组中的数已在主函数中赋予。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # define M 3 # define N 4 void fun(int a[M][N],int b[N]) { } main() { int c[ M ][ N ]={{10,22,15,30}, {19,33,45,38}, {20,22,66,40}}; int p[ N ],i,j,k; FILE *out; printf(The original data is : \n); for(i=0;iM;i++){ for(j=0;jN;j++) printf(%6d,c[i][j]); printf(\n); } fun(c,p); printf(\nThe result is:\n); for(k=0;kN;k++) printf( %4d ,p[ k ]); printf(\n); out=(outfile.dat,w); for(k=0;kN;k++) fprintf(out,%d\n,p[ k ]); fclose(out); } 【答案及难度指数】★★★ int i,j,max; for(j=0;jN;j++) //访问每一列 { max=a[0][j]; //将最大值初值赋成每一列的第一个元素 for(i=0;iM;i++) //求每一列的最大值 { if(a[i][j]max) max=a[i][j]; } b[j]=max; //将最大值存入b } 第17套 1.在主函数中从键盘输入若干个数放入数组a中,用0结束输入但不计入数组。下列给定程序中,函数fun的功能是:输出数组元素中小于平均值的元素。例如,数组中元素的值依次为34 54 675 456 453 121,则程序的运行结果为34 54 121。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(___1___,int n) { double count=0.0; double average=0.0; int i=0; for(i=0;in;i++) ___2___; average=___3___; for(i=0;in;i++) if(a[i]average) { if(i%5==0) printf(\n); printf(%d,,a[i]); } } main() { int a[1000]; int i=0; printf(\nPlease enter datas(end with 0):); do { scanf(%d,a[i]); } while(a[i++]!=0); fun(a,i-1); } 【答案及难度指数】★★ (1)int a[] (2)count+=a[i] (3)count/n 2.下列给定程序中函数fun的功能是:将长整型数中每一位上为奇数的数依次取出,构成一个新数放在b中。高位仍在高位,低位仍在低位。例如,当a中的数为87653142时,则b中的数为7531。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h void fun(long a,long *b) { int d; long s=1; /********error********/ b=0; while(a0) { d=a%10; /*******error*********/ if(d%2==0) { *b=d*s+*b; s*=10; } a /=10; } } main() { long a,b; printf(\nPlease enter a: ); scanf(%ld,a); fun(a,b); printf(The result is: %ld\n,b); } 【答案及难度指数】★★ (1)*b=0; (2)if(d%2!=0) 3.学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组student中,请编写函数fun,它的功能是按分数的高低排列学生的记录,高分在前。 请勿改动主函数main与其他函数中的任何SCORE; void fun(SCORE a[ ]) { } main () { SCORE student[M]={{002,69},{004, 85},{001,91},{007,72},{008,64},{006,87},{015,85},{012,64},{014,91},{011,66}}; int i;FILE *out; fun(student); printf(The data after sorted :\n); for(i=0;iM;i++) { if((i)%4==0) printf(\n); printf(%s %4d ,student[i].num, student[i].s); } printf(\n); out= (outfile.dat,w); for(i=0;iM;i++) { if((i)%4==0 i) fprintf(out,\n); fprintf(out,%4d,student[i].s); } fprintf(out,\n); fclose (out); } 【答案及难度指数】★★★ int i,j; SCORE t; for(i=0;iM-1;i++) //第一次取第一个元素 for(j=i;jM;j++) //将所有的元素与第一个元素进行比较,得出最大的元素 if(a[i].sa[j].s) //如果当前元素比第一元素大,则进行交换 { t=a[i]; a[i]=a[j]; a[j]=t; 第十八套 1.请补充fun函数,该函数的功能是求不超过给定自然数的各奇数之和。例如,输入34,则输出结果为289。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h int fun(int n) { int i,sum; sum=___1___; for(i=1;___2___;i+=2) sum+=i; return sum; } main() { int a; do { printf(\nPlease enter natural numbers a:); scanf(%d,a); } while(a=0); printf(\n不超过给定自然数%d的各奇数之和为%d\n,a,fun(a)); } 【答案及难度指数】★★ (1)0 (2)i=n 2.下列给定程序中,函数fun的功能是:计算str所指字符串中含有s所指字符串的数目,并作为函数值返回。 请修改函数fun中的错误或在横线处填上适当的内容并把横线删除,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h # define M 80 int fun(char *str,char *s) { int n; char *p,*r; n=0; /*******error*********/ p=str[0]; *r=s; while(*p) { if(*r==*p) { r++; if(*r==‘\0’) { n++; /*******error*********/ ___填 空___ } } p++; } return n; } main() { char s1[M],s2[M]; int num; printf(\nPlease enter string s1 :); gets(s1); printf(\nPlease enter substring s2 :); gets(s2); num=fun(s1,s2); num=printf(\nThe result is:m=%d\n, num); } 【答案及难度指数】★★ (1)r=s; (2)r=s; 3.请编写一个函数void fun(char*q),其功能是:将字符串q中所有下标为奇数位置上的字母转换为大写字母(若该位置上不是字母,则不转换)。 例如,若输入asdf2asd,则应输出aSdF2AsD。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h void fun(char *q) { } void main(void) { char str[100]; FILE *out; printf(\nPlease enter an character string within 50 characters:\n); gets(str); printf(\n\nAfter changing,the string\n %s,str); fun(str) ; printf(\nbecomes\n %s,str); out= (outfile.dat,w); strcpy(str,After changing,the string); fun(str); fprintf(out,%s,str); fclose(out); } 【答案及难度指数】★★★ int i,n=0; char *p=q; //工作指针p指向字符串q while(*p) { n++; //取字符串的长度 p++; } for(i=0;in;i++) if((q[i]=‘a’q[i]=‘z’)i%2!=0) //判断i下标位置字符是小写字母和奇数位置 q[i]=q[i]-32; //小写字母转换为大写字母 q[i]=‘\0’; 第 十九套 1.请在函数fun的横线上填写表达式,使从键盘上输入一个整数m,输出斐波纳契数列。斐波纳契数列是一种整数数列,其中每个数等于前面两个数之和,例如,0 1 1 2 3 5 8…… 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h int fun(int m); main() { int i,m=0; scanf(%d,m); for(i=0;im;i++) printf(%d ,fun(i)); } int fun(int m) { if(___1___) return 0; else if(___2___) return 1; else return ___3___; } 【答案及难度指数】★★ (1)m==0 (2)m==1 (3)fun(m-1)+fun(m-2) 2.下列给定程序中,函数fun的功能是:通过某种方式实现两个变量值的交换,规定不允许增加语句和表达式。例如变量x中的值原为1,y中的值原为2,程序运行后x中的值为2,y中的值为1。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h int fun(int *a,int b) { int temp; /*******error*********/ temp=a;a=b; /*******error********/ return (b); } main() { int x=1,y=2; printf(x,y %d %d\n,x,y); y=fun(x,y); printf(the result is %d %d\n,x,y); } 【答案及难度指数】★★ (1)temp=*a;*a=b; (2)return (temp); /return temp; 3.请编写一个函数void fun(char*t,int p[]),统计在t字符串中a到z26个字母各自出现的次数,并依次放在p所指数组中。 例如,当输入字符串sdfssdrefggrthdg后,程序的输出结果应该是: 00031231000000000231000000 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(char *t,int p[]) { } main() { char a[2000]; int b[26],i; FILE *out; printf(\nPlease a char string:); scanf(%s,a); fun(a,b); for(i=0;i26 ;i++) printf(%d,b[i]); printf(\n); fun(a bosom friend afar brings a distant land near,b); out=(outfile.dat,w); for(i=0;i26;i++) fprintf(out,%d\n,b[i]); fclose(out); } 【答案及难度指数】★★★ int j; for(j=0;j26;j++) p[j]=0; //初始化累加数组 while(*t) //不是字符串的结束符,进行循环 { switch(*t) //转向t指向的字符 { //下面根据t值的不同,对p中对应的数组值对应元素加1 case ‘a’: p[0]++;break; case ‘b’: p[1]++;break; case ‘c’: p[2]++;break; case ‘d’: p[3]++;break; case ‘e’: p[4]++;break; case ‘f’: p[5]++;break; case ‘g’: p[6]++;break; case ‘h’: p[7]++;break; case ‘i’: p[8]++;break; case ‘j’: p[9]++;break; case ‘k’: p[10]++;break; case ‘l’: p[11]++;break; case ‘m’: p[12]++;break; case ‘n’: p[13]++;break; case ‘o’: p[14]++;break; case ‘p’: p[15]++;break; case ‘q’: p[16]++;break; case ‘r’: p[17]++;break; case ‘s’: p[18]++;break; case ‘t’: p[19]++;break; case ‘u’: p[20]++;break; case ‘v’: p[21]++;break; case ‘w’: p[22]++;break; case ‘x’: p[23]++;break; case ‘y’: p[24]++;break; case ‘z’: p[25]++;break; } t++; //指向下一个字符 } 第20套 1.请补充fun函数,该函数的功能是求一维数组a[N]的平均值,并对所得结果进行四舍五入保留两位小数。例如,当a[10]={ 23.1,12.3,5.3,56.4,10.0,13.7,24.5,42,1.2,9.9}时,输出结果为:average=19.840000。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h double fun(double a[10]) { int i; long temp; double average=0.0; double sum=0.0; for(i=0;i10;i++) ___1___; average=sum/10; average=___2___; temp=___3___; average=(double) temp /100; return average; } main() { double average,a[10]={23.1,12.3,5.3, 56.4,10.0,13.7,24.5,42,1.2,9.9}; int i; printf(\nThe data :\n); for(i=0;i10;i++) printf(%6.1f,a[i]); printf(\n\n); average=fun(a); printf(The average=%f\n\n,average); } 【答案及难度指数】★★ (1)sum+=a[i] (2)average*1000 (3)(average+5)/10 下列给定程序中fun函数的功能是:将n个无序整数从小到大排序。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include stdlib.h fun(int n,int *b) { int i,j,p,t; for(j=0;jn-1;j++) { p=j; /*******error*********/ for(i=j+1;in-1;i++) if(b[p]b[i]) /******error**********/ t=i; if(p!=j) { t=b[j]; b[j]=b[p]; b[p]=t; } } } putarr(int n,int *z) { int i; for(i=1;i=n;i++,z++) { printf(%4d,*z); if(!(i%10)) printf(\n); } printf(\n); } main() { int a[10]={0,4,2,8,6},n=5; printf(\n\nBefore sorting %d numbers: \n,n); putarr(n,a); fun(n,a); printf(\nAfter sorting %d numbers:\n,n); putarr(n,a); } 【答案及难度指数】★★ (1)for(i=j+1;in;i++) (2)p=i; 3.编写函数fun,函数的功能是:根据以下公式计算,计算结果作为函数值返回。 S=1+111++L+1+21+2+31+2+3+L+n p通过形参传入,例如,若p的值为21时,函数的值为1.909091。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # includeconio.h # includestdio.h # includestring.h float fun(int n) { } main() { int n; float str; FILE *out; printf(\nPlease the integer n:); scanf(%d,n); str=fun(n); printf(The result is: %f\n,str); str=fun(10); out=(outfile.dat,w); fprintf(out,%f,str); fclose(out); } 【答案及难度指数】★ int k; float str=1.0,sum=1.0; for(k=2;k=n;k++) { sum=sum+k; //求得每一项的分母 str=str+1/sum; //级数累加求和 } return str; 第21套 1.请补充fun函数,该函数的功能是:分类统计一个字符串中元音字母和其他字符的个数(不区分大小写)。例如,输入UdsaeyiEosu,结果为A:1 E:2 I:1 O:1 U:2 other:4。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # define N 100 void fun(char *s,int a[]) { char *r=s; int i=0; for(i=0;i6;i++) ___1___; while(*r) { switch (*r) { case ‘A’: case ‘a’: a[0]++; break; case ‘E’: case ‘e’: a[1]++; break; case ‘I’: case ‘i’: a[2]++; break; case ‘O’: case ‘o’: a[3]++; break; case ‘U’: case ‘u’: a[4]++; break; default: ___2___; } ___3___; } } main() { char s[N],yy[5]=AEIOU; int i; int a[6]; printf(Please a sing to count: \n); gets(s); printf(The sing is: \n); puts(s); fun(s,a); for(i=0;i5;i++) printf(\n%c:%d,yy[i],a[i]); printf(\nother:%d,a[i]); } 【答案及难度指数】★★ (1)a[i]=0 (2)a[5]++ (3)r++ 2.假定整数不重复数列{99,2,6,1,3,4,-1}中的数存放在数组s中。下列给定程序中,函数fun的功能是:删除数列中值为a的元素,同时将其他元素前移。sum中存放的是数列中元素的个数。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # define M 100 fun(int *x,int sum,int a) { int temp=0,j; x[sum]=a; while(a!=x[temp]) temp=temp+1; if(temp==sum) { return-1; } else { /*******error*********/ for(j=temp;jsum;j++) x[j+1]=x[j]; return sum-1; } } main() { int s[M]={99,2,6,1,3,4,-1},a,sum,j; sum=8; printf(The array:\n); for(j=0;jsum;j++) printf(%5d,s[j]); printf(\nPlease insert data want to deleted:); scanf(%d,a); printf(Delete :%d\n,a); sum=fun(s,sum,a); if(sum==-1) { printf(***Not be found!***\n\n); } else { printf(The array after delete :\n); for(j=0;jsum;j++) printf(%5d,s[j]); printf(\n\n); } } 【答案及难度指数】★★★ x[j]=x[j+1]; 3.请编写一个函数void fun(char orig[],char result[],int flg),其功能是:删除一个字符串中指定下标的字符。其中,orig指向原字符串,删除后的字符串存放在result所指的数组中,flg中存放指定的下标。 例如,输入一个字符串:Hello World,然后输入4,则调用该函数后的结果为:Hell World。 请勿改动主函数main与其他函数中的任何//如果字符下标不满足题目要求的标志flg { result[m]=orig[n]; //原始串的字符赋值给新串result m++; } result[m]=‘\0’; //新串末尾加上结束符 第22套 1.s是全部由小写字母字符和空格字符组成的字符串,由len传入字符串的长度,请补充fun函数,该函数的功能是:统计字符串s中的单词数,结果由变量len传回。每个单词之间都由空格隔开,并且字符串s开始不存在空格。例如,s=welcome welcome,结果为:len=2。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define M 100 void fun(char *s,int *len) { int j,n=0; for(j=0;___1___;j++) if(s[j]=‘a’ s[j]=‘z’ s[j+1] ==‘ ‘ || s[j+1]==‘\0’) ___2___; ___3___; } main() { char s[M]; int len=0; printf(Enter a sing :\n); gets(s); while(s[len]) len++; fun(s,len); printf(The lenber of word is : %d\n\n,len); } 【答案及难度指数】★★ (1)j*len (2)n++ (3)*len=n 2.下列给定程序中函数fun的功能是:用选择法对数组中的n个元素按从小到大的顺序进行排序。 请修改程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # define M 100 void fun(int sort[],int n) { int i,j,temp,p; for(j=0;jn-1;j++) { /********error********/ p=j for(i=j;in;i++) if(sort[i]sort[j]) { /******error********/ p=j; temp=sort[p]; sort[p]=sort[j]; sort[j]=temp; } } } main() { int sort[M]={23,3,67,-2,9,-6,27,12}, i,num=8; printf(before sort:); for(i=0;inum;i++) printf(%d,,sort[i]); printf(\n); fun(sort,num); printf(after sort:); for(i=0;inum;i++) printf(%d,,sort[i]); printf(\n); } 【答案及难度指数】★★★ (1)p=j; (2)p=i; 3.请编写一个函数fun,它的功能是:计算并输出给定整数m的所有因子(不包括1与自身)之和。规定m的值不大于1000。 例如,若主函数从键盘给m输入的值为111,则输出为sum=40。 请勿改动主函数main与其他函数中的任何); scanf(%d,n); num=fun(n); printf(num=%d\n,num); out= (outfile.dat,w); fprintf(out,%d\n,fun(123)); fprintf(out,%d\n,fun(456)); fprintf(out,%d\n,fun(789)); fclose (out); } 【答案及难度指数】★★★ int sum=0,i; //累计的求和变量初始化为0 for(i=2;i=m-1;i++) //循环判求因子及求和 if(m%i==0) //判断i是m的因子 sum+=i; //累加因子 return sum; //返回因子和 第23套 s是一个由数字和字母字符组成的字符串,由变量len传入字符串长度。请补充fun函数,该函数的功能是把 字符串s中的数字字符转换成数字并存放到整型数组a中,函数返回数组a的长度。例如,s=Abc123e456hui7890,结果为:1234567890。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define M 80 int a[M]; int fun(char s[],int a[],int len) { int j,m=0; for(j=0;jlen;j++) if(s[j]=‘0’ ___1___ s[j]=‘9’) { a[m]=___2___; m++; } return ___3___; } main() { char s[M]; int len=0,m,j; printf(Please a string :\n); gets(s); while(s[len]) len++; m=fun(s,a,len); printf(\nThe result string ); for(j=0;jm;j++) printf(%d,a[j]); } 【答案及难度指数】★★ (1) (2)s[j]-’0’ 2.下列给定程序中,函数fun的功能是:在字符串s中找出ASCII码值最小的字符,将其放在第一个位置上;并将该字符前的原字符向后顺序移动。例如,调用fun函数之前给字符串输入:asdfEiopr,调用后字符串中的内容为:Easdfiopr。 请修改程序中的错误,使程序能得出正确结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h /********error********/ void function(char *str); { char MIN,*temp; int n=0; MIN=str[n]; while(str[n]!=0) { if(MINstr[n]) { /********error********/ MIN=str[n]; str=temp+n; (3)m } n++; } while(tempstr) { *temp=*(temp-1); temp--; } str[0]=MIN; } main() { char s[100]; printf( a string to move: ); gets(s); printf(\nThe string your inter: ); puts(s); function(s); printf(\nThe string after moving: ); puts(s); printf(\n\n); } 【答案及难度指数】★★★ (1)void function(char *str) (2)temp=str+n; 3.请编写函数fun,它的功能是:求Fibonacci数列中大于a(a3)的最小的一个数,结果由函数返回。其中Fibonacci数列F(n)的定义为: F(0)=0,F(1)=1 F(n)=F(m-1)+F(m-2) 例如,当a=500时,函数值为610。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include math.h # include stdio.h int fun(int a) { } main() { int m; FILE *out; m=500; printf(m=%d,F=%d\n,m,fun(m)); out= (outfile.dat,w); for(m=500;m3000;m+=500) fprintf(out,%d\n,fun(m)); fclose (out); } 【答案及难度指数】★ int x=1,y=1,z=0,i; for(i=4;i=a;i++) //根据题干中的限制要求进行循环,小于a { if(za) //求解数列中数值 { z=x+y;//前两项的求和赋于z x=y; //x为第一项 y=z; //y为第二项 } else break; } return z; 第24套 1.从键盘输入一组无符号整数并保存在数组a[M]中,以整数0结束输入,要求这些数的最大位数不超过4位,其元素的个数通过变量len传入fun函数。请补充fun函数,该函数的功能是:从数组a中找出个位和十位的数字之和小于5的所有无符号整数,结果保存在数组b中,其个数由fun函数返回。例如当a[8]={123,11,23,222,42,333,14,5451}时,x[2]={11,222}。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define M 500 int fun(int a[],int x[],int len) { int j,m=0; int t,s; for(j=0;jlen;j++) { t=___1___; s=a[j]/10%10; if((t+s)5) ___2___; } return ___3___; } main() { int a[M]; int b[M]; int len=0,m=0,j=0; printf( lenber :\n); do { scanf(%u,a[len]); } while(a[len++]!=0); m=fun(a,b,len); printf(\nb=); for(j=0;jm-1;j++) printf(%u ,b[j]); } 【答案及难度指数】★★ (1)a[j]%10 (2)x[m++]=a[j] (3)m 2.n个有序整数数列已放在一维数组中,给定下列程序,函数fun的功能是:利用折半查找算法查找整数m在数组中的位置。若找到,则返回其下标值;反之,则返回-1。 折半查找的基本算法是:每次查找前先确定数组中待查的范围low和high(lowhigh),然后把m与中间位置(mid)中元素的值进行比较。如果m的值大于中间位置元素中的值,则下一次的查找范围放在中间位置之后的元素中;反之,下一次的查找范围放在中间位置之前的元素中。直到lowhigh,查找结束。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # define M 5 /*******error*********/ void fun(int b[],int n) { int low=0,high=M-1,mid; while(low=high) { mid=(low+high)/2; if(nb[mid]) high=mid-1; /********error********/ else if(n=b[mid]) low=mid+1; else return(mid); } return (-1); } main() { int i,b[M]={ 9,13,45,67,89},j,n; printf(b 数组中的数据如下:); for(i=0;iM;i++) printf(%d,,b[i]); printf(Enter n:); scanf(%d,n); j=fun(b,n); if(j=0) printf(n=%d,index=%d\n,n,j); else printf(Not be found!\n); } 【答案及难度指数】★★★ (1)int fun(int b[],int n) (2)if(nb[mid]) 3.请编一个函数float fun(double c),函数的功能是对变量c中的值保留2位小数,并对第三位进行四舍五入(规定c中的值为正数)。 例如,若c值为1.234,则函数返回1.230000;若c值为1.235,则函数返回1.240000。 注意:部分源程序给出如下。 请勿改动主函数main与其他函数中的任何); scanf (%f,a); printf(The original data is: ); printf(%f \n\n,a); printf(The result : %f\n,fun(a)); out=(outfile.dat,w); fprintf(out,%f,fun(3.141593)); fclose(out); } 【答案及难度指数】★ long t; float s; c=c*1000; //扩大1000倍 t=(c+5)/10; //扩大后加五,进行四舍五入的进位判断 s=(float)t/100.0; //缩小为原来的数值 return s; 第25套 1.请补充main函数,该函数的功能是:从一个字符串中截取前面若干个给定字符数的子字符串。其中,s1指向原字符串,截取后的字符串存放在s2所指的字符数组中,n中存放预截取的字符个数。例如,当s1=xsdfgehrt,然后输入5,则s2=xsdfg。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # define N 100 main() { char s1[N],s2[N]; int n,i; printf(Enter the string:\n); gets(s1); printf(Enter the position of the string deleted:); scanf(___1___); for(i=0;in;i++) ___2___; s2[i]=‘\0’; printf(The new string is:%s\n,__3___); } 【答案及难度指数】★★ (1)%d,n (2)s2[i]=s1[i] (3)s2 2.下列给定程序中,函数fun的功能是根据整型形参n,计算如下公式的值: x=1+1111+++L+2´23´34´4n´n 例如,若n中的值为5,则应输出1.463611。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h double fun(int n) { double x=1.0; int i; /********error********/ for(i=2;in;i++) /******error**********/ x+=1/(i*i); return (x); } main() { int n=5; printf(\nThe result is %1f\n,fun(n)); } 【答案及难度指数】★★★ (1)for(i=2;i=n;i++) (2)x+=1.0/(i*i); 3.编写函数fun,它的功能是计算并输出下列级数和: 111F=++L+1´22´3m(m+1) 例如,当m=5时,函数值为0.833333。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h double fun(int m) { } main() { int i; FILE *out; printf(%f\n,fun(5)); out= (outfile.dat,w); for(i=5;i10;i++) fprintf(out,%f\n,fun(i)); fclose (out); 【答案及难度指数】★ double f=0.0; //级数求值的变量初始化 int i; for(i=1;i=m;i++) //在m项循环中求级数数列的和 f=f+1.0/(i*(i+1)); //数列求和,数列中的每一项1.0/(i*(i+1) return f; } 第26套 1.请补充main函数,该函数的功能是:从字符串s中取出所有数字字符,并分别计数,把结果保存在数组a中并输出,把其他字符保存在a[10]中。 例如,当str1=12312300abc8976542时,结果为0:2 1:2 2:3 3:2 4:1 5:1 6:1 7:1 8:1 9:1 other character:3。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include conio.h main() { int j,a[11]; char *s=adfsdasa1232312323; char *t=s; printf(The origial data is :\n); puts(s); for(j=0;j11;j++) a[j]=0; while(*t) { switch (___1___) { case ‘0’: a[0]++; break; case ‘1’: a[1]++; break; case ‘2’: a[2]++; break; case ‘3’: a[3]++; break; case ‘4’: a[4]++; break; case ‘5’: a[5]++; break; case ‘6’: a[6]++; break; case ‘7’: a[7]++; break; case ‘8’: a[8]++; break; case ‘9’: a[9]++; break; ___2___; } ___3___; } printf(The result \n); for(j=0;j10;j++) printf(\n%d:%d,j,a[j]); printf(\nother character:%d,a[j]); } 【答案及难度指数】★★ (1)*t (2)default: a[10]++(3)t++ 2.下列给定程序中,函数fun的功能是:从str所指字符串中,找出s所指子串的个数作为函数值返回。例如,当str所指字符串中的内容为asdfghasdfgh,s所指字符串的内容为as,则函数返回整数2。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h int fun(char *str,char *s) { int m; char *p,*r; m=0; while(*str) { p=str; r=s; while(*r) /********error********/ if(r==p) { r++; p++; } else { break; } /*******error*********/ if(r==‘\0’) m++; str++; } return m; } main() { char str[100],s[100]; int n; printf(\nPlease enter string str:); scanf(%s,str); printf(\nPlease enter substring s:); scanf(%s,s); n=fun(str,s); printf(\nThe result is: n=%d\n,n); } 【答案及难度指数】★★★ (1)if(*r==*p) (2)if(*r==‘\0’) 3.编写函数fun,它的功能是:根据以下公式求的值,结果由函数值带回。m与n为两个正整数且要求mn。 m!P=n!(m-n)! 例如,m=10,n=5时,运行结果为252.000000。 请勿改动主函数main与其他函数中的任何 //求n! result=result/temp; //求m!/n! for(temp=1.0,i=1;i=m-n;i++) temp=temp*i; //求(m-n)! result=result/temp; //求m!/n!(m-n)! return result; 第27套 1.请补充fun函数,该函数的功能是:先将在字符串str中的字符按逆序存放到t中,然后把str中的字符按正序连接到t的后面。例如,str中的字符串为abc时,则t中的字符串应为cbaabc。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h void fun(char *str,char *t) { int n,i; n=strlen(str); for(i=0;in;i++) t[i]=str[___1___]; for(i=0;in;i++) t[n+i]=str[i]; t[___2___]=‘\0’; } main() { char str[100],t[100]; printf(\nPlease enter string :); scanf(%s,str); fun(str,t); printf(The result is: %s\n,t); } 【答案及难度指数】★★ (1)n-i-1 (2)2*n 2.下列给定程序中,函数fun的功能是:在字符串的最前端加入n个*号,形成新串,并且覆盖原串。注意:字符串的长度最长允许为79。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include string.h # include conio.h void fun(char str[],int n) { char a[80],*p; int i; /********error********/ str=p; for(i=0;in;i++) a[i]=‘*’; do { a[i]=*p; i++; /*******error*********/ ___填 空___ } while(*p); /*******error*********/ a[i]=‘0’; strcpy(str,a); } main() { int n; char str[80]; printf(\nEnter a string :); gets(str); printf(\nThe string %s\n,str); printf(\nEnter n(number of *): ); scanf(%d,n); fun(str,n); printf(\nThe string after inster: %s\n,str); } 【答案及难度指数】★★★ (1)p=str; (2)p++; (3)a[i]=‘\0’; 3.编写函数fun,该函数的功能是:从字符串中删除指定的字符。同一字母的大、小写按不同字符处理。 例如,若程序执行时输入字符串为:just a test,从键盘上输入字符t,则输出后变为:jus a es。 如果输入的字符在字符串中不存在,则字符串照原样输出。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h void fun(char s[],int a) { } main() { static char str[]=just a test; char ch; FILE *out; printf(original string:%s\n,str); printf(please a character:); scanf(%c,ch); fun(str,ch); printf(str[]=%s\n,str); strcpy(str,just a test); fun(str,’a’); out=(outfile.dat,w); fprintf(out,%s,str); fclose(out); } 【答案及难度指数】★★★ int i=0; char*p; p=s; while(*p) //循环判断每一个字符 { if(*p!=a) //如果不等于指定字符 { s[i]=*p; //将原值不动赋值给s i++; //字符串s加1 } p++; //如果是指定的字符,则后移 } s[i]=‘\0’; 第28套 1.请补充fun函数,该函数的功能是:用来求出数组的最小元素在数组中的下标并存放在k所指的存储单元中。例如,输入如下整数:121,333,444,111,555,666, 980,431,451,343,则输出结果为:111,3。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int *s,int t,int ___1___) { int j,min; min=s[0]; for(j=0;jt;j++) if(___2___) { min=s[j]; *i=___3___; } } main() { int a[10]={121,333,444,111,555,666, 980,431,451,343},i; fun(a,10,i); printf(%d,%d\n,a[i],i); } 【答案及难度指数】★★ (1)*i (2)s[j]min (3)j 2.下列给定程序中,函数fun的功能是:求出两个非零正整数的最大公约数,并作为函数值返回。例如,若给n和m分别输入27和81,则输出的最大公约数为27。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h int fun(int a,int b) { int r,temp; /*******error*********/ if(ab) { temp=a; b=a; b=temp; } r=a%b; while(r!=0) { a=b; b=r; r=a%b; } /********error********/ return (a); } main() { int n,m,a; printf( n m : ); scanf(%d%d,n,m); printf(n=%d m=%d\n\n,n,m); a=fun(n,m); printf(The maximun common divisor is %d\n\n,a); } 【答案及难度指数】★★★ (1)a=b; (2)return (b); 3.下列程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int b[][N]),该函数的功能是:使数组左下半三角元素的值会全部置成0。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # include stdlib.h # define N 3 void fun(int b[][N]) { } main() { int b[N][N],i,j; FILE *out; printf(**********\n); for(i=0;iN;i++) { for(j=0;jN;j++) { b[i][j]=rand()%10; printf(%4d,b[i][j]); } printf(\n); } fun(b); printf(THE RESULT\n); for(i=0;iN;i++) { for(j=0;jN;j++) printf(%4d,b[i][j]); printf(\n); } for(i=0;iN;i++) for(j=0;jN;j++) b[i][j]=i*N+j+1; fun(b); out=(outfile.dat,w); for(i=0;iN;i++) { for(j=0;jN;j++) fprintf(out,%4d,b[i][j]); fprintf(out,\n); } fclose(out); } 【答案及难度指数】★★ int i,j; for(i=0;iN;i++) //对行进行控制 for(j=0;j=i;j++) //对列进行控制 b[i][j]=0; //把列下标小于等于行下标的值赋0 第 29 1.数组a[N]保存着一组3位数的无符号正整数,其元素的个数通过变量len传入fun函数。请补充fun函数,该函数的功能是:从数组a中找出个位和百位的数字相等的所有无符号整数,结果保存在数组yy中,其个数由fun函数返回。 例如,当a[6]={111,323,677,456,987,999}时,b[3]={111,323,999}。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # define N 500 int fun(int a[],int bb[],int len) { int i,n=0; int g,b; for(i=0;ilen;i++) { g=___1___; b=a[i]/100; if(g==b) ___2___; } return ___3___; } main() { int a[8]={111,323,677,456,987,999}; int b[N]; int len=0,n=0,i=0; len=6; printf(The original data\n ); for(i=0;ilen;i++) printf(%u ,a[i]); printf(\n\n\n); n=fun(a,b,len); printf(\nb=); for(i=0;in;i++) printf(%u ,b[i]); } 【答案及难度指数】★★ (1)a[i]%10 (2)bb[n++]=a[i] (3)n 2.下列给定程序中,函数fun的功能是:逐个比较x、y两个字符串对应位置中的字符,把ASCII相等或值小的字符依次存放在到z数组中,形成一个新的字符串。例如,若x中的字符串为AbceDEfG,y中的字符串为ABdefgC,则z中的字符串应为ABceDEC。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include string.h void fun(char *a,char *b,char *z) { /*******error*********/ int i=1; /*******error*********/ while(*a!=*b) { if(*a*b) z[i]=*b; else z[i]=*a; if(*a) a++; if(*b) b++; i++; } } main() { char x[10]=AbceDEfG,y[10]=ABdefgC, z[80]={‘\0’}; fun(x,y,z); printf(The string x:); puts(x); printf(The string y:); puts(y); printf(The result:); puts(z); } 【答案及难度指数】★★★ (1)int i=0; (2)while(*a || *b) 3.请编写一个函数unsigned fun(unsigned n),n是一个大于10的无符号整数,若n是m(m≥2)位的整数,则函数求出n的后m-1位的数作为函数值返回。 例如,n值为1234,则函数返回234。 请勿改动主函数main与其他函数中的任何 //将无符号数m赋值给t while(t10) //只对大于一位的无符号数进行操作,否则返回0 { if(t/10) p=t%10; //截取一位 s=s+p*s1; //组成新数s s1=s1*10; //权数升级,例如级数10,升级为100 t=t/10; //删除一位 } return s; 第30 1.请补充fun函数,该函数的功能是:把一个整数转换成字符串,并倒序保存在字符数组s中。例如,当n=123时,s=321。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # define M 80 char s[M]; void fun(long int n) { int j=0; while(___1___) { s[j]=___2___; n /=10; j++; } ___3___; } main() { long int n=1234567; printf(The origial data \n); printf(n=%ld,n); fun(n); printf(\n%s,s); } 【答案及难度指数】★★ (1)n0 (2)n%10+’0’ (3)s[j]=‘\0’ 2.下列给定程序中,函数fun的功能是:将str所指字符串中的字母转换为按字母序列的后续字母(Z转换A,z转换为a),其他字符不变。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include ctype.h # include conio.h void fun(char *str) { /*******error*********/ while(*str!=‘@’) { if(*str=‘A’*str=‘Z’ || *str=‘a’ *str=‘z’) { if(*str==‘Z’) *str=‘A’; else if(*str==‘z’) *str=‘a’; else *str+=1; } /*******error*********/ (*str)++; } } main() { char str[80]; printf(\n Enter a string with length80. :\n\n ); gets(str); printf(\n The string: \n\n ); puts(str); fun(str); printf(\n\n The Cords:\n\n ); puts(str); } 【答案及难度指数】★★★ (1)while(*str) /while(*str!=‘\0’) /while(*str!=0) (2)str++; 3.请编一个函数fun(char *str),该函数的功能是把字符串中的); gets (a); printf(The original string is: ); puts(a); fun(a); printf(\n); printf(The string after modified : ); puts (a); strcpy(a,Welcome!); fun(a); out=(outfile.dat,w); fprintf(out,%s,a); fclose(out); } 【答案及难度指数】★★ char ch; int i,m,n; i=0; m=n=strlen(str)-1; //求字符串str长度 while(i(n+1)/2) //循环逆置交换 { ch=str[i]; str[i]=str[m]; str[m]=ch; i++; m--; } 第 31套 1.请补充main函数,该函数的功能是求方程ax2+bx+c=0的两个实数根。方程的系数a、b、c从键盘输入,如果判别式(disc=b*b-4*a*c)小于0,则要求重新输入a、b、c的值。 例如,当a=2,b=1,c=3时,显示:disc=-13000000, again!;当a=1,b=2,c=1时,输入方程的两个根分别是:x1=-1.00,x2=-1.00。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include math.h # include stdio.h main() { double a,b,c,disc,x1,x2; do { printf( a,b,c: ); scanf(%lf,%lf,%lf,a,b,c); disc=b*b-4*a*c; if(disc0) printf(disc=%lf \n again! \n,disc); } while(___1___); printf(The result is \n); x1=(-b+___2___ (disc))/(2*a); x2=(-b-___3___ (disc))/(2*a); printf(\nx1=%6.2lf\nx2=%6.2lf\n,x1,x2); } 【答案及难度指数】★★ (1)disc0 (2)sqrt (3)sqrt 2.下列给定程序中,fun函数的功能是:将q所指字符串中每个单词的最后一个字母改成大写(这里的单词是指由空格隔开的字符串)。例如, 若输入:Good luck,good luck! 则应输出:GooD luck,gooD luck! 请修改程序中的错误之处,得出正确的结果。 注意:不要改动main函数,不能删行,也不能更改程序的结构。 # include string.h # include ctype.h # include stdio.h void fun(char *q) { int i=0; for(;*q;q++) /********error********/ if(i) { if(q==‘ ‘) { i=0; /*******error*********/ *q=toupper(*(q-1)); } } else { i=1; } } main() { char s[64]; int d; printf(\nPlease enter an english sentence within 63 letters: ); gets(s); d=strlen(s); s[d+1]=‘ ‘; s[d+1]=0; printf(\n\nBefor changing: %s,s); fun(s); printf(\nAfter changing:\n %s,s); } 【答案及难度指数】★★★ (1)if(*q==‘ ‘) (2)*(q-1)=toupper(*(q-1)); 3.编写程序,实现矩阵(3行列)的转置(即行列互换)。 例如,若输入下面的矩阵: 1 2 3 4 5 6 7 8 9 则程序输出: 1 4 7 2 5 8 3 6 9 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h void fun(int a[3][3]) { } main() { int i,j; int a[3][3]={{1,2,3}, {4,5,6}, {7,8,9}}; FILE *out; for(i=0;i3;i++) { for(j=0;j3;j++) printf(%7d,a[i][j]); printf(\n); } fun(a); printf(Converted a:\n); out=(outfile.dat,w); for(i=0;i3;i++) { for(j=0;j3;j++) { printf(%7d,a[i][j]); fprintf(out,%7d,a[i][j]); } printf(\n); fprintf(out,\n); } fclose(out); } 【答案及难度指数】★★ int i,j,temp; for(i=0;i3;i++) //对行进行循环 for(j=0;ji;j++) //对列进行循环,a[i][j]和a[j][i]进行交换 { temp=a[i][j]; a[i][j]=a[j][i]; a[j][i]=temp; } 第32 1.请补充main函数,该函数的功能是:先以只写方式打开文件file.dat,再把字符串s中的字符保存到这个磁盘文件中。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include stdlib.h # define N 100 main() { FILE *f; int i=0; char ch; char s[N]=Welcome!; if((f=(___1___ ,w))==NULL) { printf(cannot open file.dat\n); exit(0); } while(s[i]) { ch=s[i]; ___2___; putchar(ch); i++; } ___3___; 【答案及难度指数】★★ (1)file.dat (2)fputc(ch,f) (3)fclose(f) 2.下列给定程序中,函数fun的功能是:求三个数的最小公倍数。例如,给变量a、b、c分别输入15、11、2,则输出结果应当是330。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h int fun(int x,int y,int z) { int i,temp,n,m; /*******error*********/ i=1; temp=m=n=1; /********error********/ while(temp!=0 m!=0 n!=0) { i=i+1; temp=i%x; m=i%y; n=i%z; } return i; } main() { int a,b,c,i; printf( a b c: ); scanf(%d%d%d,a,b,c); printf(a=%d,b=%d,c=%d \n,a,b,c); i=fun(a,b,c); printf(The minimal common multiple is : %d\n,i); } 【答案及难度指数】★★★ (1)i=0; (2)while(temp!=0 || m!=0 || n!=0) 3.编写函数fun,它的功能是:利用以下所示的简单迭代方法求方程cos(y)-y=0的一个实根。 yn+1=cos(yn) 迭代步骤如下: (1)取y1初值为0.0。 (2)y0=y1,把y1的值赋给y0。 (3)y1=cos(y0),求出一个新的y1。 (4)若y0-y1的绝对值小于0.000001,则执行步骤(5),否则执行步骤(2)。 (5)所求y1就是方程cos(x)-y=0的一个实根,作为函数值返回。 程序将输出结果Result=0.739085。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include math.h # include stdio.h float fun() { } main() { FILE *out; float cos=fun(); printf(Result=%f\n,cos); out=(outfile.dat,w); fprintf(out,%f,cos); fclose(out); } 【答案及难度指数】★★ float y1=0.0,y0; do { //进行迭代 y0=y1; y1=cos(y0); } while(fabs(y0-y1)=1e-6); //判断迭代循环条件 return y1; //返回结果 第33 1.请补充main函数,该函数的功能是:计算两个自然数n1和n2(n210000)之间所有数的和,n1和n2从键盘输入。 例如,当n1=1,n2=100时,sum=5050。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include conio.h main() { int n1,n2; long sum; ___1___; printf(Please two numbers n1,n2\n); scanf(%d,%d,n1,n2); while(n1=n2) { ___2___; n1++; } printf(sum=%___3___\n,sum); } 【答案及难度指数】★★ (1)sum=0 (2)sum+=n1 (3)ld 2.下列给定程序中,函数fun的功能是:将str所指字符串的正序和反序进行连接,形成一个新串放在s所指 的数组中。例如,当str所指字符串为abc时,则s所指字符串中的内容应为abccba。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h /*******error*********/ void fun(char str,char s) { int i,n; n=strlen(str); for(i=0;in;i++) s[i]=str[i]; for(i=0;in;i++) s[n+i]=str[n-1-i]; /*******error*********/ s[2*n-1]=‘\0’; } main() { char str[50],s[50]; printf(\nPlease enter string S:); scanf(%s,str); fun(str,s); printf(\nThe result is : %s\n,s); } 【答案及难度指数】★★★ (1)void fun(char *str,char *s) (2)s[2*n]=‘\0’;/s[n+i]=‘\0’;/s[2*n]=0; 3.请编写一个函数fun,它的功能是:根据以下公式求π的值(要求满足精度0.0005,即某项小于0.0005时停止迭代): p 211´2´31´2´3´L´n++L+33´5´73´5´7´L´(2n-1)=1+ 程序运行后,如果输入精度0.0005,则程序输出为3.140578。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include math.h double fun(double e) { } main() { double y; FILE *out; printf( e:); scanf(%lf,y); printf(\ne=%lf,PI=%lf\n,y,fun(y)); out=(outfile.dat,w); fprintf(out,e=%lf,PI=%lf\n,0.00003, fun(0.00003)); fclose(out); } 【答案及难度指数】★★ double s; float n,t,pi; t=1;pi=0;n=1.0;s=1.0; //对各个累加项,累加积等赋初始化值 while((fabs(s))=e) //精度判断 { pi+=s; //pi存放累加和 t=n/(2*n+1); //每一项 s*=t; //累积 n++; } pi=pi*2; //求得π值 return pi; 第34 请补充fun函数,该函数的功能是把数组a中的数按从大到小排列。数组的值及元素个数从主函数中输入。 例如,输入2 1 3 ,结果为3 2 1。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 100 void fun(int a[],int n) { int i,j,t; for(i=0;___1___;i++) for(j=0;___2___;j++) if(a[j] a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } main() { int i=0,n=0; int a[N]; printf(Please number of data:\n); scanf(%d,n); printf(Please data:\n); while(in) { printf(a[%d]=,i); scanf(%d,a[i]); i++; } fun(a,n); printf(The result is\n); for(i=0;in;i++) printf(%4d,a[i]); } 【答案及难度指数】★★ (1)in (2)jn-1 2下列给定程序中,函数fun的功能是:依次取出字符串中所有字母字符,形成新的字符串,并取代原字符串。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include conio.h void fun(char *t) { int m,n; /*******error*********/ for(m=0,n=0;t[m]!=‘\0’;m++) if(t[n]=‘0’t[m]=‘a’ t[m]=‘z’) t[n]=t[m]; /*******error*********/ t[n]=\0; } main() { char a[40]; printf(\nEnter a string :); gets(a); printf(\n\nThe string is : %s\n,a); fun(a); printf(\n\nThe string of changing is : %s\n,a); } 【答案及难度指数】★★★ (1)t[n++]=t[m]; (2)t[n]=‘\0’; 3.请编写一个函数fun,它的功能是:将s所指字符串中所有下标为奇数位置上的字母转换为小写(若该位置上不是字母,则不转换)。 例如,若输入ABC1bCABCabc,则应输出AbC1bcAbCabc。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h void fun(char *s) { } main() { char str[101]; FILE *out; printf(\n Please enter an string within 100 characters:\n); gets(str); printf(\n\nAfter changing,the string\n %s\n,str); fun(str); printf(\nbecomes \n %s\n,str); out=(outfile.dat,w); strcpy(str,Please enter an string within 80 characters:); fun(str); fprintf(out,%s,str); fclose(out); } 【答案及难度指数】★★ int i,n; n=strlen(s); //取字符串长度 for(i=1;in;i+=2) if(s[i]=‘A’s[i]=‘Z’) //判断字符是否为大写字母 s[i]=s[i]+32;//对大写字母进行转换 第35 1.请补充main函数,该函数的功能是:从键盘输入一组字符串,以0结束输入,并显示出这个字符串。 例如,输入abcdef0,结果显示abcdef。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何 (2)s[i]!=‘0’ (3)%c,s[j] 2.下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点赋值。函数fun的功能是将单向链表结点(不包括头结点)数据域为偶数的值累加起来,并且作为函数值返回。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include conio.h # include stdlib.h typedef struct a { int data; struct a *next; } NODE; int fun(NODE *h) { int sum=0; NODE *p; p=h-next; /*******error*********/ while(p-next) { if(p-data%2==0) sum+=p-data; /*******error*********/ p=h-next; } return sum; } NODE *link(int n) { NODE *h,*p,*s; int i; h=p=(NODE*)malloc(sizeof(NODE)); for(i=1;in;i++) { s=(NODE*)malloc(sizeof(NODE)); s-data=rand()%16; s-next=p-next; p-next=s; p=p-next; } p-next=NULL; return h; } printlink(NODE *h) { NODE *p; p=h-next; printf(\n\nTHE LIST :\n\n HEAD); while(p) { printf(-%d ,p-data); p=p-next; } printf(\n); } main() { NODE *head; int sum; head=link5); printlink(head); sum=fun(head); printf(\nThe result SUM=%d,sum); } 【答案及难度指数】★★★ (1)while(p!=NULL) (2)p=p-next; 3.请编写一个函数fun,它的功能是:求出一个2×M整型二维数组中最小元素的值,并将最小值返回调用函数。 请勿改动主函数main与其他函数中的任何//第一重循环 for(j=0;jN;j++) //第二重循环 if(a[i][j]min) //把当前元素与min进行比较 min=a[i][j];//若当前元素小于min,则最小值赋值为当前元素 return min; //返回最小值 第36 1.请补充main函数,该函数的功能是:把字符串str1中的非空格字符拷贝到字符串str2中。 例如,若字符串str1=nice to meet you!,则拷贝后的字符串str2=nicetomeetyou!。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # define LEN 80 main() { static char s1[LEN]=Just a test!; char s2[LEN]; int i=0,j=0; printf(s1\n ); puts(s1); while(s1[i]) { if(___1___) s2[j++]=s1[i]; ___2___; } printf(s2 \n ); for(i=0;ij;i++) printf(%c,s2[i]); } 【答案及难度指数】★★ (1)s1[i]!=‘ ‘ (2)i++ 2.下列给定程序中,函数fun的功能是:将字符串str中位于奇数位置的字符或ASCII码为偶数的字符依次放入字符串s中。例如,字符串中的数据为AABBCCDDEEFF,则输出应当是ABBCDDEFF。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h # define N 100 void fun(char *str,char s[]) { int i,j=0; /*******error*********/ for(i=0;i(int)strlen(str);i++) if(i%2 str[i]%2==0) s[j++]=str[i]; /*******error*********/ s[i]=‘\0’; } main() { char str[N],s[N]; printf(\nPlease enther string s:); gets(str); fun(str,s); printf(\nThe result is : %s\n,s); } 【答案及难度指数】★★★ (1)if(i%2 || str[i]%2==0) / if(i%2!=0 || str[i]%2==0) (2)s[j]=‘\0’; / s[j]=0; 3.请编写函数fun,其功能是:将两个两位数的正整数x、y合并成一个整数放在z中。合并的方式是:将x数的十位和个位依次放在z的千位和十位上,y的十位和个位依次放在z的百位和个位上。 例如,当x=12 y=34,调用该项函数后,z=1324。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int x,int y,long *z) { } main () { int x,y; long z; FILE *out; printf( x,y:); scanf(%d%d,x,y); fun(x,y,z); printf(The result is: %d\n,z); out= (outfile.dat,w); for(x=10;x20;x++) { fun(x,109-x,z); fprintf(out,%d\n,z); } fclose (out); } 【答案及难度指数】★★ *z=(x/10)*1000+(y/10)*100+(x%10)*10+y%10; 第37 1.给定程序的功能是计算并输出下列级数的前N项之和SN,直到SN大于a为止。 234N+1SN=+++L+123N a的值通过形参传入。 例如,若a的值为10.0,则函数值为10.717857。 请勿改动主函数main与其他函数中的任何 (2)i++ (3)return num 2. 下列给定程序中,函数fun的功能是:从num个学生的成绩中统计出低于平均分的学生人数,此人数由函数值返回,平均分存放在形参average所指的存储单元中。例如,若输入10名学生的成绩: 69.5 79.5 89 87 67 90 65 75 88 56 则高于平均分的学生人数为5(平均分为76.599998)。 请修改程序中的错误,使程序能统计出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # define M 100 int fun(float *str,int n,float *averager) { float average,temp=0.0; int sum=0,k,j; /*******error*********/ for(k=0;kn;k++) temp=str[k]; average=temp/n; for(j=0;jn;j++) if(str[j]average) sum++; /*******error*********/ *averager=average; return sum; } main() { float str[30],averager; int num,p; printf(\n num of students: ); scanf(%d,num); printf(\n mark of these %d students :\n ,num); for(p=0;pnum;p++) scanf(%f,str+p); printf(\nThe number of students below the average is: %d\n,fun(str,num,averager)); printf(The average mark=%f\n,averager); } 【答案及难度指数】★★★ (1)temp+=str[k]; (2)*averager=average; 3.请编写函数fun,其功能是:将str所指字符串中下标为偶数同时ASCII值为奇数的字符删除,str中剩余的字符形成的新串放在s所指的数组中。 例如,若str所指字符串中的内容为ABCDEFG12345,其中字符C的ASCII码值为奇数,在数组中的下标为偶数,因此必须删除;而字符1的ASClI码值为奇数,在数组中的下标也为奇数,因此不应当删除,其他以此类推。最后s所指的数组中的内容应是BDF12345。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h void fun(char *str,char s[]) { } main() { char str[100],s[100]; FILE *out; printf(\nPlease enter string :); scanf(%s,str); fun(str,s); printf(\nThe result is : %s\n,s); out= (outfile.dat,w); strcpy(str,Please enter string :); fun(str,s); fprintf(out,%s,s); fclose (out); } 【答案及难度指数】★★ int i,j=0,n=strlen(str); //取字符串的长度 for(i=0;in;i++) if(i%2==0str[i]%2!=0); //第i个字符下标为偶数,其ASCII码是奇数 else { //若不满足以上判断,将第i个字符赋值给新串s s[j]=str[i]; j++; } s[j]=‘\0’; //加尾符 第38 1.给定程序中,函数fun的功能是:将形参指针所指结构体数组中的三个元素按num成员进行升序排列。 请勿改动主函数main与其他函数中的任何PERSON; void fun(PERSON ___1___) { ___2___ a; if(student[0].numstudent[1].num) { a=student[0]; student[0]=student[1]; student[1]=a; } if(student[0].numstudent[2].num) { a=student[0]; student[0]=student[2]; student[2]=a; } if(student[1].numstudent[2].num) { a=student[1]; student[1]=student[2]; student[2]=a; } } main() { PERSON student[]={5,Rose,2, Charl,6,Kate}; int i; fun(___3___); printf(\nThe result is :\n); for(i=0;i3;i++) printf(%d,%s\n,student[i].num, student[i].name); } 【答案及难度指数】★★ (1)*student (2)PERSON (3)student 2. 下列给定程序中,函数fun的功能是:将str所指字符串中出现的temp1所指子串全部替换成temp2所指子字符串,所形成的新串放在result所指的数组中。在此处,要求temp1和temp2所指字符串的长度相同。例如,当str所指字符串中的内容为sdfadijfsdfifdsdf,temp1所指子串中的内容为sdf,temp2所指子串中的内容为000时,在result所指的数组中的内容应为000adijf000ifd000。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h /*******error*********/ void fun(char *str,*temp1,*temp2,*result) { char *p,*r,*a; strcpy(result,str); while(*result) { p=result; r=temp1; /*******error*********/ while(r) if(*r==*p) { r++; p++; } else { break; } if(*r==‘\0’) { a=result; r=temp2; while(*r) { *a=*r; a++; r++; } result+=strlen(temp2); } else { result++; } } } main() { char str[200],temp1[200],temp2[200], result[200]; printf(\n the test string str:); scanf(%s,str); printf(\n the first substring temp1:); scanf(%s,temp1); printf(\n the second substring temp2:); scanf(%s,temp2); if(strlen(temp1)==strlen(temp2)) { fun(str,temp1,temp2,result); printf(\nThe combin result is :%s\n,result); } else { printf(Error :strlen(temp1)!= strlen(temp2)\n); } } 【答案及难度指数】★★★ (1)void fun(char *str,char *temp1, char *temp2,char *result) (2)while(*r) 3.编写函数fun,它的功能是:求m以内(不包括m)同时能被3与7整除的所有自然数之和的平方根a,并作为函数值返回。 例如,若m为500时,函数值a=76.131465。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include math.h # include stdio.h double fun(int m) { } main() { FILE *out ; printf(s=%f\n,fun(500)); out= (outfile.dat,w); fprintf(out,%f,fun(200)); fclose (out); } 【答案及难度指数】★★ double a=0.0; //平方根赋初值 int i; for(i=1;im;i++) if(i%3==0i%7==0) //选出被3与7整除的所有自然数 a=a+i; //选出的自然数求和 a=sqrt(a); //和的平方根 return a; //返回平方根 第39 1.请补充main函数,该函数的功能是:计算四个学生各科的平均分。 例如,当score[N][M]={ {83,65,63},{89,93,95},{90, 63,80},{56,75,77}}时,则平均分为:79.5,74.0,78.8。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # define N 4 # define M 3 main() { int i,j; static float score[N][M]= { {83,65,63}, {89,93,95}, {90,63,80}, {56,75,77} }; static float a[N]; for(i=0;iM;i++) a[i]=0.0; for(i=0;i___1___;i++) for(j=0;j___2___;j++) a[j]+=score[i][j]; for(i=0;iM;i++) printf(subject%d\taverage= %5.1f\n,i+1,___3___); return 0; } 【答案及难度指数】★★ (1)N (2)M y=60。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include conio.h /********error********/ void fun(int x,int y) { int t; /*******error*********/ t=y;y=x;x=t; } main() { int x,y; printf(Enter x,y: ); scanf(%d%d,x,y); fun(x,y); printf(x=%d y=%d\n,x,y); } 【答案及难度指数】★★★ (1)void fun(int *x,int *y) (2)t=*y;*y=*x;*x=t; 3.请编写函数fun,其功能是:将str所指字符串中ASCII值为奇数的字符删除,串中剩余字符形成一个新串放在s所指的数组中。 例如,若str所指字符串中的内容为asdf,则s所指的数组中的内容应是df。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h void fun(char *str,char s[]) { } main() { char str[100],s[100],m[]=Please enter string :; FILE *out ; printf(m); scanf(%s,str); fun(str,s); printf(\nThe result is :%s\n,s); out= (outfile.dat,w); fun(m,s); (3)a[i]/N 2.下列给定程序中,函数fun的功能是:实现两个整数的交换。例如,给x和y分别输入60和65,输出为:x=65 fprintf(out,%s,s); fclose (out); } 【答案及难度指数】★★ int i,j=0,n; n=strlen(str); //求得指定字符的长度 for(i=0;in;i++) //根据字符长度,对字符依次进行判断 if(str[i]%2==0) //判断的i个字符ASCII码是否是偶数 { s[j]=str[i]; //将ASCII码字符复制到s中 j++; //s下标执行加1操作 } s[j]=‘\0’; //新串加尾符 第40 1.请补充main函数,该函数的功能是:输出一个N×N矩阵,要求非对角线上的元素赋值1,对角线元素赋值0。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何the result \n); for(i=0;in;i++) { printf( \n\n); for(j=0;jn;j++) printf(%4d,a[i][j]); } } 【答案及难度指数】★★ (1)a[i][j]=1 (2)0 (3)j==n-1-i 2.下列给定程序中函数fun的功能是:从低位开始取出长整型变量x中偶数位上的数,依次构成一个新数放在y中。例如,当x中的数为123456时,则y中的数应为135。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ void fun(long x,long y) { long t=10; x /=10; *y=x%10; /*******error*********/ while(x0) { x=x/100; *y=x%10*t+*y; t=t*10; } } main() { long x,y; printf(\nPlease enter s:); scanf(%ld,x); fun(x,y); printf(The result is:%ld\n,y); } 【答案及难度指数】★★★ (1)void fun(long x,long *y) (2)while(x0) 3. 请编写函数fun,其功能是:将两个两位数的正整数x、y合并成一个整数放在z中。合并的方式是:将x的十位和个位依次放在z的百位和个位上,y的十位和个位依次放在z的十位和千位上。 例如,当x=12 y=34,调用该函数后,z=4132。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int x,int y,long *z) { } main () { int x,y; long z; FILE *out ; printf( x,y:); scanf (%d%d,x,y); fun(x,y,z); printf(The result is : %ld\n,z); out=(outfile.dat,w); for(x=20;x50;x+=3) { fun(x,109-x,z); fprintf(out,%ld\n,z); } fclose (out); } 【答案及难度指数】★★ *z=(y%10)*1000+(x/10)*100+(y/10)*10+x%10; 第41 给定程序中,函数fun的功能是:将形参student所指结构体数组中年龄最小者的数据作为函数值返回,并在main函数中输出。 请勿改动主函数main与其他函数中的任何%d\n,__3__, min.age); } 【答案及难度指数】★★ (1)*student (2)student[i].age (3)min.name 2.下列给定程序中,函数fun的功能是:将s所指字符串中最后一次出现的s1所指子串替换成s2所指子串,所形成的新串放在str所指的数据中。在此处,要求s1和s2所指字符串的长度相同。例如,当s所指字符串中的内容为abcdabfabc,s1所指子串中的内容为ab,s2所指子串中的内容为99时,则在str所指的数组中的内容为abcdabf99c。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h /********error*********/ void fun(char*s,s1,s2,str) { char *p,*r,*a; strcpy(str,s); /********error*********/ while(str) { p=str; r=s1; while(*r) if(*r==*p) { r++; p++; } else { break; } if(*r==‘\0’) a=str; str++; } r=s2; while(*r) { *a=*r; a++; r++; } } main() { char s[100],s1[100],s2[100],str[100]; printf(\nPlease enter string S:); scanf(%s,s); printf(\nPlease enter substring s1:); scanf(%s,s1); printf(\nPlease enter substring s2:); scanf(%s,s2); if(strlen(s1)==strlen(s2)) { fun(s,s1,s2,str); printf(\nThe result is : %s\n,str); } else { printf(\nError : strlen(s1)!= strlen(s2)\n); } } 【答案及难度指数】★★★ (1)void fun(char *s,char *s1,char *s2,char *str) (2)while(*str) 3.学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组stu中,请编写函数fun,它的功能是:函数返回指定学号的学生数据,指定的学号在主函数中输入。若没找到指定学号,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回(用于字符串比较的函数是strcmp)。 请勿改动主函数main与其他函数中的任何SCORE; SCORE fun(SCORE *p,char *q) { } main () { SCORE stu[M]={{G002,69},{G004, 85},{G001,96},{G007,72},{G008,64},{G006,87},{G015,85},{G013,94},{G012,64},{G014,91}}; SCORE t; char m[10]; int i;FILE *out; printf(The original data :\n); for(i=0;iM;i++) { if(i%4==0) printf(\n); printf(%s %3d,stu[i].num,stu[i].s); } printf(\n\nEnter the number : ); gets (m); t=fun(stu,m); printf( The data : ); printf(\n%s %4d\n,t.num,t.s); printf(\n); out= (outfile.dat,w); t=fun(stu,G013); fprintf(out,%s %4d\n,t.num,t.s); fclose (out); } 【答案及难度指数】★★ int i; SCORE t; for(i=0;iM;i++) //在M个学号中进行循环 if(strcmp(p[i].num,q)==0) //对输入的q与所有的p[i]进行比较 { t=p[i]; //如果找到,将p[i]复制给t break; //跳出循环 } else { strcpy(t.num,); //否则将空格赋值给t中的学号 t.s=-1; //t的s域赋值-1 } return t; //返回查找结果 第42 1.请补充main函数,该函数的功能是求1+2!+3!+…+N!的和。 例如,1+2!+3!+…+9!的和为409113。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h main() { int i,n; long sum=0,temp=1; printf(\n n:\n); scanf(%d,___1___); for(i=1;i=n;i++) { temp=___2___; sum=___3___; } printf(1!+.+%d!=%ld\n,n,sum); } 【答案及难度指数】★★ (1)n (2)temp*i (3)sum+temp 2.下列给定程序中,函数fun的功能是:求出数组中最大数和次最大数,并把最大数和b[0]中的数对调、次最大数和b[1]中的数对调。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # define N 10 /********error********/ void fun(int *b,int n); { int i,m,t,j; for(i=0;i2;i++) { /*******error*********/ m=0; for(j=i+1;jn;j++) if(b[j]b[m]) m=j; t=b[i]; b[i]=b[m]; b[m]=t; } } main() { int a[N]={ 5,12,9,7,10},n=5,i; for(i=0;in;i++) printf(%d ,a[i]); printf(\n); fun(a,n); for(i=0;in;i++) printf(%d ,a[i]); printf(\n); } 【答案及难度指数】★★★ (1)void fun(int *b,int n) (2)m=i; 3.请编写函数fun,其功能是计算并输出下列多项式的值: Fn=1+1/1!+1/2!+1/3!+1/4!+…+1/m! 例如,若主函数从键盘给m输入5,则输出为F=2.716667。 请勿改动主函数main与其他函数中的任何//求m项多项式的循环 { t=1.0; //阶乘求解初始化 for(j=1;j=i;j++) t*=j; s+=1.0/t; //求得多项式的和 } return s; 第43 1.请补充fun函数,该函数的功能是:把字符串s中的字符按字符的ASCII码升序排列,处理后的字符串仍然保存在原串中,字符串及其长度作为函数参数传入。 例如,如果输入edcba,则输出为abcde。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 100 void fun(char p[],int n) { int i,j; char t; for(i=0;in;i++) for(___1___;jn;j++) if(p[i]p[j]) { t=p[j]; ___2___; p[i]=t; } } main() { int i=0,strlen=0; char s[N]; printf(Please a string:\n); gets(s); while(s[i]!=‘\0’) { strlen++; i++; } fun(s,strlen); printf(Display string \n); puts(s); } 【答案及难度指数】★★ (1)j=i (2)p[j]=p[i] 2.下列给定程序中,函数fun的功能是:从N个字符串中找出最长的字符串,并将其地址作为函数值返回。各字符串在主函数中输入,并放入一个字符串数组中。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include string.h # define N 5 # define M 81 /*******error*********/ fun(char (*q)[N]) { int i; char *p; p=q[0]; for(i=0;iN;i++) if(strlen(p)strlen(q[i])) p=q[i]; /******error**********/ return q; } main() { char s[N][M],*longest; int i; printf(Enter %d lines:\n,N); for(i=0;iN;i++) gets(s[i]); printf(\nThe N string :\n,N); for(i=0;iN;i++) puts(s[i]); longest=fun(s); printf(\nThe longest string :\n); puts(longest); } 【答案及难度指数】★★★ (1)char *fun(char (*q)[M]) (2)return p; 3.请编写函数fun,该函数的功能是:统计一行字符串中单词的个数,作为函数值返回。一行字符串在主函数中输入,规定所有单词由小写字母组成,单词之间由若干个空格隔开,一行的开始和结尾都没有空格。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # define M 100 int fun(char *str) { } main() { char s[M]; int sum=0; FILE *out; char *test[]={Welcome,this is a test string}; printf(Enter a string :\n); gets(s); sum=fun(s); printf(The number of word is : %d\n\n,sum); out=(outfile.dat,w); for(sum=0;sum2;sum++) fprintf(out,%d\n,fun(test[sum])); fclose(out); } 【答案及难度指数】★ int i,n=0; //字符统计初始值设置为0 for(i=0;istrlen(str);i++) //小于字符串长度进行字符循环判断 { if(str[i]=‘a’ str[i]=‘z’ str[i+1]==‘ ‘ || str[i+1]==‘\0’) //单词判断条件 n++; //单词统计计数器加1 } return n; //返回统计值 第44 1.请补充main函数,该函数的功能是:如果数组a的前一个元素比后一个元素大,则把它保存在数组b中并输出。 例如,输入{33,49,56,12,66,52,78,95,80,73},则输出56 66 95 80。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何STUDENT; STUDENT *fun(STUDENT a[],int m) { STUDENT b[N],*t; int i,j,k; /********error********/ *t=malloc(sizeof(STUDENT)); for(i=0;iN;i++) b[i]=a[i]; for(k=0;km;k++) { for(i=j=0;iN;i++) if(b[i].sb[j].s) j=i; /********error********/ t[k].num=b[j].num; t[k].s=b[j].s; b[j].s=0; } return t; } printresult(STUDENT a[],FILE *pf) { int i; for(i=0;iN;i++) fprintf(pf,No=%s Mark=%d\n, a[i].num,a[i].s); fprintf(pf,\n\n); } main() { STUDENT a[N]= { {01,81},{02,89},{03,66}, {04,87},{05,77},{06,90},{07,79},{08,61},{09,80},{10,71} }; STUDENT *Order; int i,m; printf(*****The Original data *****\n); printresult(a,stdout); printf(\nGive the number of the students who have better score: ); scanf(%d,m); while(m10) { printf(\nGive the number of the students who have better score: ); scanf(%d,m); } Order=fun(a,m); printf(*****THE RESULT *****\n); printf(The top :\n); for(i=0;im;i++) printf( %s %d\n,Order[i].num, Order[i].s); free(Order); } 【答案及难度指数】★★★ (1)t=(STUDENT*)malloc(sizeof(STUDENT)*m); (2)strcpy(t[k].num,b[j].num); 3. 请编写函数fun,其功能是:将两个两位正整数x、y合并成一个整数放在z中。合并的方式是:将x的十位和个位依次放在z的十位和千位上,y十位和个位依次放在z的百位和个位上。 例如,当x=12,y=34,调用该函数后,z=2314。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int x,int y,long *z) { } main() { int x,y; long z; FILE *out; printf( x,y: ); scanf(%d%d,x,y); fun(x,y,z); printf( The result is :%ld\n,z); out= (outfile.dat,w); for(x=21;x51;x+=3) { fun(x,109-x,z); fprintf(out,%ld\n,z); } fclose (out); } 【答案及难度指数】★★ *z=(x%10)*1000+(y/10)*100+(x/10)*10+y%10; 第45 1.请补充fun函数,该函数的功能是把数组a中的奇数元素按原来的先后顺序放在原数组后面。 例如,输入5,7,2,42,35,32,28,37,68,13,则输出2,42,32,28,68,5,7,35,37,13。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 10 void fun(int a[]) { int i,j=0,k=0; int b[N]; for(i=0;iN;i++) if(___1___) b[k++]=a[i]; else a[j++]=a[i]; for(i=0;___2___;i++,j++) a[j]=b[i]; } main() { int i; int a[N]={5,7,2,42,35,32,28,37,68,13}; printf(The original list is\n); for(i=0;iN;i++) printf(%4d,a[i]); fun(a); printf(\nThe result list is\n); for(i=0;iN;i++) printf(%4d,a[i]); } 【答案及难度指数】★★ (1)a[i]%2!=0 (2)ik 2.下列给定程序中,函数fun的功能是:将n(1≤n≤10)个字符串连接起来,组成一个新串,放在s所指字符串中。例如,把2个字符串as、df连起来,结果是asdf。 请修改程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h /*******error*********/ void fun(char str[][],int m,char *s) { int j,q,i; for(j=0;jm;j++) { q=strlen(str[j]); /********error********/ for(i=0;iq;i++) s[i]=str[j,i]; s+=q; s[0]=0; } } main() { int n,t; char s[10][10],p[120]; printf(\nPlease enter n:); scanf(%d,n); gets(s[0]); printf(\nPlease enter %d string:\n,n); for(t=0;tn;t++) gets(s[t]); fun(s,n,p); printf(\nThe result is : %s\n,p); } 【答案及难度指数】★★★ (1)void fun(char str[][10],int m,char *s) (2)s[i]=str[j][i]; 3.请编写函数fun,其功能是:将str所指字符串中下标为偶数的字符删除,字符串中剩余字符形成的新串放在s所指数组中。 例如,当str所指字符串中的内容为12345678,则在s所指数组中的内容应是2468。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h void fun(char *str,char s[]) { } main() { char str[100],s[100],m[]=\nPlease enter string:; FILE *out; printf(m); scanf(%s,str); fun(str,s); printf(\nThe result is :%s\n,s); out= (outfile.dat,w); fun(m,s); fprintf(out,%s,s); fclose (out); } 【答案及难度指数】★★ int i,j=0,n=strlen(str); for(i=0;in;i++) if(i%2!=0) { s[j]=str[i]; j++; } s[j]=‘\0’; 第46 1.请补充main函数,该函数的功能是:打印出满足个位上的数字、十位上的数字和百位上的数字都相等的所有三位数。 本题的结果为:111 222 333 444 555 666 777 888 999。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h main() { int x,y,z; for(x=1;x10;x++) for(y=1;y10;y++) for(z=1;z10;z++) if(x==y ___1___y==z) printf(%5d,___2___ y*10+z*100); } 【答案及难度指数】★ (1) (2)x+ 2.下列给定程序中,函数fun的功能是:比较两个字符串,将长的字符串的首地址作为函数值返回。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ double fun(char *s,char *t) { int s1=0,t1=0; char *str1,*str2; str1=s; str2=t; /*******error*********/ while(*str1) { s1++; (*str1)++; } /*******error*********/ while(*str2) { t1++; (*str2)++; } if(t1s1) return t; else return s; } main() { char p[80],q[80]; printf(\nEnter a string : ); gets(p); printf(\nEnter another string : ); gets(q); printf(\nThe longer is :\n\n%s\n, fun(p,q)); } 答案 (1)char *fun(char *s,char *t) (2)str1++; (3)str2++; 3.N名学生的成绩已在主函数中放入一个带头节点的链表结构中,a指向链表的头节点。请编写函数fun,它的功能是:找出学生的最高分,由函数返回。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include stdlib.h # define N 5 struct list { double s; struct list *next; }; typedef struct list STR; double fun(STR *a) { } STR *creat(double *s) { STR *a,*p,*q; int i=0; a=p=(STR*)malloc(sizeof(STR)); p-s=0; while(iN) { q=(STR*)malloc(sizeof(STR)); q-s=s[i]; i++; p-next=q; p=q; } p-next=0; return a; } printlist(STR *a) { STR *p; p=a-next; printf(head); do { printf(-%2.0f,p-s); p=p-next; } while(p!=0); printf(\n\n); } main() { double s[N]={69,72,85,80,68},max; STR *a; FILE *out; a=creat(s); printlist(a); max=fun(a); printf(max=%6.1f\n,max); out=(outfile.dat,w); fprintf(out,max=%6.1f,max); fclose(out); } 【答案及难度指数】★★★★ double max; STR *q=a; //设工作指针q max=a-s; //设最大值为头节点数据域 do //循环判断每一个数据域与最大值的大小关系 { if(q-smax) //如果节点数据域值大于max max=q-s;//则对数据域与最大值进行交换 q=q-next;//工作指针指向下一个节点 } while(q!=0); //判断是否为尾 return max; //返回最大值 第47 1.请补充main函数,该函数的功能是:把一维数组中的元素逆置,结果仍然保存在原数组中。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # define N 10 main() { int i,j,temp; int b[N]; for(i=0;iN;i++) b[i]=i; printf(The original list\n); for(i=0;iN;i++) printf(%4d,b[i]); for(j=0,___1___;j=i;j++,i--) { temp=b[j]; ___2___; b[i]=temp; } printf(The New list is\n); for(i=0;iN;i++) printf(%4d,b[i]); } 【答案及难度指数】★★ (1)--i (2)b[j]=b[i] 2.下列给定程序中,函数fun的功能是:为一个偶数寻找两个素数,这两个素数之和等于该偶数,并将这两个素数通过形参指针传回主函数。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include math.h void fun(int x,int *y,int *z) { int i,j,d,t; for(i=3;ix/2;i=i+2) { /********error********/ t=0; for(j=2;j=sqrt((double)i);j++) if(i%j==0) t=0; if(t==1) { /*******error*********/ d=i-x; for(j=2;j=sqrt((double)i);j++) if(d%j==0) t=0; if(t==1) { *y=i; *z=d; } } } } main() { int x,y,z; do { printf(\n x: ); scanf(%d,x); } while(x%2); fun(x,y,z); printf(\n\n%d=%d+%d\n,x,y,z); } 【答案及难度指数】★★★ (1)t=1; (2)d=x-i; 3.请编写函数fun,该函数的功能是:判断字符串是否为回文?若是则函数返回1,主函数中输出YES,否则返回0,主函数中输出NO。回文是指顺读和倒读都一样的字符串。 例如,字符串LEVEL是回文,而字符串123312就不是回文。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # define MAX 100 int fun(char *s) { } main() { char str[MAX] ; FILE *out; char *t[]={121,123,asa,abc}; int i; printf(Enter a string: ) ; gets(str) ; printf(\n\n) ; puts(str) ; if(fun(str)) printf( YES\n) ; else printf( NO\n) ; out=(outfile.dat,w); for(i=0;i4;i++) if(fun(t[i])) fprintf(out,YES\n); else fprintf(out,NO\n); fclose(out); } 【答案及难度指数】★★★★ int i,n=0,flag=1; //初始设置标识位flag=1 char *p=s; //设置工作指针 while(*p) //取字符串大小 { n++; p++; } for(i=0;in/2;i++) //循环判断字符串s是否为回文 if(s[i]==s[n-1-i]); //设置比较位j为n-1-i else //若不符合条件,标识位设为0,跳出循环 { flag=0; break; } return flag; 第48 1.请补充main函数,该函数的功能是:打印出1~99中满足个位数字的平方等于其本身的所有数。本题的结果为:1 25 36。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h main() { int i,n; for(i=1;i99;i++) { n=___1___; if(___2___) printf(%4d,i); } } 【答案及难度指数】★★ (1)i%10 (2)n*n==i 2.下列给定程序中,函数fun的功能是:用冒泡法对5个字符串按由小到大的顺序进行排序。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include string.h # define MAX 20 /*******error*********/ void fun(char (*str)[5]) { int i,j; char *p; for(i=0;i5;i++) { for(j=i+1;j5;j++) { /********error********/ if(strcmp(*(str+i),str+j)0) { p=*(str+i); /********error********/ *(str+i)=str+j; *(str+j)=p; } } } } main() { int i; char *str[5],s[5][MAX]; for(i=0;i5;i++) str[i]=s[i]; printf(\nEnter 5 sting(1 sting at each line): \n); for(i=0;i5;i++) scanf(%s,str[i]); fun(str); printf(The strings after sorting:\n); for(i=0;i5;i++) printf(%s\n,str[i]); } 【答案及难度指数】★★★ (1)void fun(char *str[5]) (2)if(strcmp(*(str+i),*(str+j))0) (3)*(str+i)=*(str+j); 3.请编写一个函数,用来删除字符串中的所有空格。 例如,输入we l come,则输出为welcome。 请勿改动主函数main与其他函数中的任何//如果p不是空格 { s[i]=*p; //将*p这个值赋于s[i] i++; //s下标加1 } p++; //如果p指向的字符是空格,则p指向下一个位置,不向s赋值 } s[i]=‘\0’; 第49 1.请补充main函数,该函数的功能是:从键盘输入一个字符串,即一个指定字符,然后把这个字符及其后面的所有字符全部删除,结果仍然保存在原串中。 例如,输入1234567,指定字符为’4’,则输出123。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # define N 100 main() { int i=0; char s[N]; char ch; printf(Please a string:\n); gets(s); printf(Please a charater:\n); scanf(%c,ch); while(s[i]!=‘\0’) { if(s[i]==ch) ___1___; ___2___; } s[i]=___3___; printf(The result is\n); puts(s); } 【答案及难度指数】★★ (1)break (2)i++ (3)’\0’ 2.下列给定程序中,函数fun的功能是:首先把y所指字符串中的字符按逆序存放,然后将x所指字符串中的字符和y所指字符串中的字符,按排列的顺序交叉合并到z所指数组中,过长的剩余字符接在z所指数组的尾部。例如,当x所指字符串中的内容为1234,y所指字符串中的内容为abcdefg时,z所指数组中的内容应该为lg2f3e4dcba;而当x所指字符串中的内容为abcdef,y所指字符串中的内容为1234时,z所指数组中内容应该为a4b3c2dlef。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h void fun(char *x,char *y,char *z) { int i,j; char ch; i=0; j=strlen(y)-1; /*******error*********/ while(ij) { ch=y[i]; y[i]=y[j]; y[j]=ch; i++; j--; } while(*x || *y) { if(*x) { *z=*x; z++; x++; } if(*y) { *z=*y; z++; y++; } } /********error********/ z=0; } main() { char s1[100],s2[100],s3[200]; printf(\nEnter s1 string : ); scanf(%s,s1); printf(\nEnter s2 steing : ); scanf(%s,s2); fun(s1,s2,s3); printf(\nThe result is : %s\n,s3); } 【答案及难度指数】★★★ (1)while(ij) / while(ji) (2)*z=0; / *z=‘\0’; 3.假定输入的字符串中只包含字母和#号。请编写函数fun,它的功能是:将字符串中的前导#号全部移到字符串的尾部。 例如,若字符串中的内容为###a#b#c#d###,移动后,字符串中的内容应当是a#b#c#d######。在编写函数时,不得使用C语言提供的字符串函数。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h void fun(char *s) { } main() { char str[81],*p; FILE *out; char test[2][80]={###A###B#CD######, ###a#b#c#d###}; int i; printf(Enter a string:\n); gets(str); fun(str); printf(The string after moveing:\n); puts(str); out=(outfile.dat,w); for(i=0;i4;i++) { fun(test[i]); fprintf(out,%s\n,test[i]); } fclose(out); } 【答案及难度指数】★★★★ int i=0,n=0;//#号统计器n赋初始值0 char *p; p=s; //工作指针p指向字符串s while(*p==‘#’) //循环统计前导#号数目n { n++; p++; } while(*p) //截取#号字符 { s[i]=*p; i++; p++; } while(n!=0) //在串尾开始添加n个#号 { s[i]=‘#’; i++; n--; } s[i]=‘\0’; 第50 1.请补充main函数,该函数的功能是:输出方程组a+b=52,a+2b=60的一组正整数解。本题的结果是a=44,b=8。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h main() { int i,j; for(i=0;i100;i++) for(j=0;j100;j++) if(i+j==52 ___1___ i+2*j==60) printf(The answer a=%2d, b=%2d,___2___); } 【答案及难度指数】★★ (1) (2)i,j 2. 下列给定程序中,函数fun的功能是:找出一个大于给定整数n且紧随n的素数,并作为函数值返回。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h int fun(int n) { int i,j; for(i=n+1;;i++) { for(j=2;ji;j++) /********error********/ if(i%j!=0) break; /********error********/ if(ji) return(i); } } main() { int m; printf(\nplease enter data: ); scanf(%d,m); printf(%d\n,fun(m)); } 【答案及难度指数】★★★ (1)if(i%j==0) (2)if(j=i) 3.某学生的记录由学号、5门课程成绩和平均分组成,学号和5门课程的成绩已在主函数中给出。请编写函数fun,它的功能是:求出该学生的平均分,并放在记录的ave成员中。请自已定义正确的形参。 例如,若学生的成绩是72、83、90、68.5、71.5,则他的平均分应当是77.000。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # define M 5 typedef struct { char num[10]; double s[M]; double ave; } SCORE; void fun(SCORE *p) { } main() { SCORE s={GA005, 72,83,90,68.5,71.5}; int i; FILE *out; fun(s); printf(The %s’s student data:\n, s.num); for(i=0;iM;i++) printf(%4.1f\n,s.s[i]); printf(\nave=%7.3f\n,s.ave); out= (outfile.dat,w); fprintf(out,The %s’s student data:\n, s.num); for(i=0;iM;i++) fprintf(out,%4.1f\n,s.s[i]); fprintf(out,\nave=%7.3f\n,s.ave); fclose (out); 【答案及难度指数】★★★★ double t=0.0; //初始化平均值 int i; for(i=0;iM;i++) t+=p-s[i]; //求得总分 t/=M; //根据人数,求平均分 p-ave=t;//将平均分赋值到记录ave成员中 第51 1.请补充fun函数,该函数的功能是:返回字符数组中指定字符的个数,指定字符从键盘输入。 请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 100 int fun(char s[],char ch) { int i=0,sum=0; while(___1___) { if(___2___) sum++; i++; } ___3___; } main() { int sum; char str[N],ch; printf( a string:\n); gets(str); printf( a character:\n); scanf(%c,ch); sum=fun(str,ch); printf(Number of %c: %d,ch,sum); } 【答案及难度指数】★★ (1)s[i] (2)s[i]==ch (3)return sum 2.下列给定程序中,函数fun的功能是根据整型形参n,计算如下公式的值: 1111x=+++L+100´100200´200300´300n´n 例如,若n=1000,则应输出0.000155。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ fun(int n) { double x=0,d; int i; /*******error*********/ for(i=100,i=n,i+=100) { d=(double)i*(double)i; x+=1.0/d; } return (x); } main() { int m=1000; printf(\nThe result is %lf\n,fun(m)); } 【答案及难度指数】★★★ (1)double fun(int n) (2)for(i=100;i=n;i+=100) 2.请编写函数fun,它的功能是:求出str所指字符串中指定字符的个数,并返回此值。 例如,若输入字符串asdfasdf,输入字符a,则输出2。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h # define N 100 int fun(char *str,char c) { } main() { char s[N],ch; FILE *out; printf(\nPlease enter a string:); gets(s); printf(\nPlease enter a char:); ch=getchar(); printf(\nThe number of the char is: %d\n,fun(s,ch)); out= (outfile.dat,w); strcpy(s,The number of the char is: ); fprintf(out,%d,fun(s,’a’)); fclose (out); }【答案及难度指数】★★★ (1)double fun(int n) (2)for(i=100;i=n;i+=100) 3.请编写函数fun,它的功能是:求出str所指字符串中指定字符的个数,并返回此值。 例如,若输入字符串asdfasdf,输入字符a,则输出2。 请勿改动主函数main与其他函数中的任何//进入字符串循环 { if(*str==c) //判断是否为指定字符 n++; //如果是指定字符,统计变量加1 str++; //指向字符串下一个字符 } return n; 100 1.请补充fun函数,该函数的功能是:从键盘输入一个下标n,把数组a中比元素a[n]小的元素放在它的左边,比它大的元素放在它的右边,排列成的新数组仍然保存在原数组中。 例如,数组a={ 33,55,66,44,77,22,88,99,11,10},输入2,则结果输出33 55 44 22 11 10 66 77 88 99。 请勿改动主函数main与其他函数中的任何请修改程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h long fun(int x,int n) { int j; /*******error*********/ long a=0,t=1; /********error*******/ for(j=0;j=n;j++) t=t*10+x; a=t; for(j=1;jn;j++) { /*******error*********/ t=t%10; a=a-t; } return(a); } main() { int x,n; printf(\nPlease enter x and n:); scanf(%d%d,x,n); printf(The value of fun is %ld\n, fun(x,n)); } 【答案及难度指数】★★★ (1)long a=0,t=0; (2)for(j=0;jn;j++) (3)t=t/10; 3.请编写函数fun,其功能是:计算并输出: 例如,若主函数从键盘给m输入10后,则输出为F=104.478749。 请勿改动主函数main与其他函数中的任何); scanf(%d,m); f=fun(m); printf(\n\nf=%f\n\n,f); out=(outfile.dat,w); for(m=0;m10;m++) fprintf(out,%f\n,fun(m+20)); fclose(out); } 【答案及难度指数】★★ int i; double f=1.0,p=1.0; //初始化累加求和变量f,每一项p for(i=2;i=m;i++) { p+=pow(i,0.5); //多项式中的每一项p f+=p; //累计多项式中各项的和 } return f; 99 1.给定程序中,函数fun的功能是:将N×N矩阵中元素的值按列右移1个位置,右边被移出矩阵的元素绕回左边。 例如,N=3,有下列矩阵: 1 2 3 4 5 6 7 8 9 计算结果为: 3 1 2 6 4 5 9 7 8 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 3 void fun(int (*a)[N]) { int i,j,t; for(i=0;i___1___;i++) { t=a[i][ ___2___]; for(j=N-1;j0;j--) a[i][j]=a[i][j-1]; ___3___=t; } } main() { int i,j,a[][N]={1,2,3,4,5,6,7,8,9}; printf(The original array:\n); for(i=0;iN;i++) { for(j=0;jN;j++) printf(%2d ,a[i][j]); printf(\n); } fun(a); printf(\nThe result is:\n); for(i=0;iN;i++) { for(j=0;jN;j++) printf(%2d ,a[i][j]); printf(\n); } } 【答案及难度指数】★★★★ (1)N (2)N-1 (3)a[i][0] 2.下列给定程序中,函数fun的功能是:读入一个字符串(长度20),将该字符串中的所有字符按ASCII码升序排序后输出。例如,若输入asdf,则应输出adfs。 请修改程序中的错误,使它能统计出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include string.h # include stdio.h void fun(char s[]) { char ch; int i,j; /*******error********/ for(i=strlen(s);i;i--) for(j=0;ji;j++) /********error*******/ if(s[j]s[j+1]) { ch=s[j]; s[j]=s[j+1]; s[j+1]=ch; } } main() { char str[81]; printf(\nPlease enter a character string: ); gets(str); printf(\n\nBefore sorting:\n %s ,str); fun(str); printf(\nAfter sorting decendingly: \n %s,str); } 【答案及难度指数】★★★ (1)for(i=strlen(s)-1;i;i--) / for(i=strlen(s)-1;i0;i--) (2)if(s[j]s[j+1]) 3.请编写函数fun,它的功能是:计算并输出m(包括m)以); scanf(%d,m); f=fun(m); printf(\n\nf=%f\n,f); out=(outfile.dat,w); for(m=0;m10;m++) fprintf(out,%f\n,fun(m+20)); fclose(out); } 【答案及难度指数】★★ int i; double sum=0.0; for(i=1;i=m;i++) if(i%3==0||i%7==0) //选出能被3或7整除的数 sum+=1.0/i; //求得这些倒数的和 return sum; 98 给定程序中,函数fun的功能是:有N×N矩阵,以主对角线为对称线,对称元素相加并将结果存放在下三角元素中,右上三角元素置为0。 例如,若N=4,有下列矩阵: 21 12 13 24 25 16 47 38 29 11 32 54 42 21 33 10 计算结果为: 21 0 0 0 37 16 0 0 42 58 32 0 66 59 87 10 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 4 void fun(int (*a)___1___) { int i,j; for(i=1;iN;i++) { for(j=0;ji;j++) { ___2___=a[i][j]+a[j][i]; ___3___=0; } } } main() { int i,j,a[][N]={21,12,13,24,25, 16,47,38,29,11,32,54,42,21,33,10}; printf(\nThe original array:\n); for(i=0;iN;i++) { for(j=0;jN;j++) printf(%2d ,a[i][j]); printf(\n); } fun(a); printf(\nThe result is:\n); for(i=0;iN;i++) { for(j=0;jN;j++) printf(%2d ,a[i][j]); printf(\n); } } 【答案及难度指数】★★★★ (1)[N] (2)a[i][j] (3)a[j][i] 2.下列给定程序中,函数fun的功能是:计算n的5次方的值(规定2n8),通过形参指针传回主函数,并计算该值的个位、十位、百位上数字之和作为函数值返回。例如,4的5次方是1024,其低3位数的和值是6。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include math.h int fun(int n,int *q) { int b,c,i; /********error********/ b=0; /*******error********/ c=1; for(i=1;i=5;i++) b=b*n; *q=b; for(i=1;i=3;i++) { c=c+b%10; /*******error*********/ c=c/10; } return c; } main() { int n,sum,a; do { printf(\nEnter n(2n8): ); scanf(%d,n); } while(n=2 || n=8); sum=fun(n,a); printf(\n\nThe result:\n value=%d sum=%d\n\n,a,sum); } 【答案及难度指数】★★★ (1)b=1; (2)c=0; (3)b=b/10; 3.请编写函数fun,其功能是计算并输出下列多项式的值: 例如,若主函数从键盘给m输入10后,则输出为F=1.818182。 请勿改动主函数main与其他函数中的任何); scanf(%d,m); f=fun(m); printf(\n\nf=%f\n\n,f); out=(outfile.dat,w); for(m=0;m10;m++) fprintf(out,%f\n,fun(m+50)); fclose(out); } 【答案及难度指数】★★ int i,j; double sum=0.0,t; for(i=1;i=m;i++) { t=0.0; for(j=1;j=i;j++) t+=j; sum+=1.0/t; } return sum; 97 1.给定程序中,函数fun的功能是计算N×N矩阵的主对角线元素和反向对角线元素之和, 并作为函数值返回。注意:要求先累加主对角线元素中的值,然后累加反向对角线元素中的值。 例如,若N=4,有下列矩阵: 11 12 13 21 34 45 1 2 34 56 8 9 10 5 14 24 fun函数首先累加11、45、8、24,然后累加21、1、56、10,函数的返回值为176。 请勿改动主函数main与其他函数中的任何请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ void fun(char *str,int num[5]); { int j,i=5; /*******error*********/ for(j=0;ji;j++) num[i]=0; for(;*str;str++) { i=-1; /*******error*********/ switch (str) { case ‘a’: case ‘A’: { i=0; break; } case ‘e’: case ‘E’: { i=1; break; } case ‘i’: case ‘I’: { i=2; break; } case ‘o’: case ‘O’: { i=3; break; } case ‘u’: case ‘U’: { i=4; break; } } if(i=0) num[i]++; } } main() { char s[81]; int sum[5],i; printf(\nPlease enter a string: ); gets(s); fun(s,sum); for(i=0;i5;i++) printf(%d,sum[i]); printf(\n); } 【答案及难度指数】★★★ (1)void fun(char *str,int num[5]) (2)num[j]=0; (3)switch(*str) 3.请编写函数fun,其功能是:计算并输出给定数组(长度为5)中每相邻两个元素的平均值的平方根之和。 例如,若给定数组中的5个元素依次为4.0、23.0、34.0、45.0、18.0,则输出应为f=20.910162。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include math.h double fun(double a[5]) { } main() { double f,c[5]={4.0,23.0,34.0,45.0,18.0}; int i; FILE *out; printf(\nThe original data is :\n); for(i=0;i5;i++) printf(%6.1f,c[i]); printf(\n\n); f=fun(c); printf(f=%f\n\n,f); out=(outfile.dat,w); fprintf(out,%f,f); fclose(out); } 【答案及难度指数】★★ double sum=0.0; //初始化累计求和变量 int i,j=1; for(i=0;i5;i++) //对数组的元素进行循环操作 if(j=4) //如果累加的次数小于等于4,那么就进行累加 { sum+=sqrt((a[i]+a[i+1])/2.0); //计算累加 j++; //累加次数加1 } return sum; 96 1.请补充main函数,该函数的功能是把文 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include stdlib.h # define N 100 main() { FILE *f,*f1,*f2; int i; char c[N],ch; f=(a.dat,w); fprintf(f,Welcome!\n); fclose(f); f=(b.dat,w); fprintf(f,Just a test!\n); fclose(f); if((f=(a.dat,r))==NULL) { printf(file a cannot be opened\n); exit(0); } printf(A contents are :\n\n); for(i=0;(ch=fgetc(f))!=EOF;i++) { c[i]=ch; putchar(c[i]); } fclose(f); if((f=(b.dat,r))==NULL) { printf(file b cannot be opened\n); exit(0); } printf(B contents are :\n\n); for(i=0;(ch=fgetc(f))!=EOF;i++) { c[i]=ch; putchar(c[i]); } fclose(f); if((f1=(a.dat,a)) ___1___ (f2=(b.dat,r))) { while((ch=fgetc(f2))!=EOF) __2___; } else { printf(Can not open A B!\n); } fclose(f2); fclose(f1); printf(New a contents\n\n); if((f=(A.dat,r))==NULL) { printf(file A cannot be opened\n); exit(0); } for(i=0;(ch=fgetc(f))!=EOF;i++) { c[i]=ch; putchar(c[i]); } ___3___; } 【答案及难度指数】★★★★ (1) (2)fputc(ch,f1) (3)fclose(f) 2.下列给定程序中,函数fun的功能是:求整数a的b次方的低3位值。例如,整数5的6次方为15625,此数的低3位值为625。 请修改函数中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h long fun(int a,int b,long *p) { int i; long t=1; /******error*********/ for(i=1;ib;i++) t=t*a; *p=t; /*******error********/ t=t/1000; return t; } main() { long t,r; int a,b; printf(\n a and b: ); scanf(%ld%ld,a,b); t=fun(a,b,r); printf(\n\na=%d,b=%d,r=%ld, last=%ld\n\n,a,b,r,t); } 【答案及难度指数】★★★ (1)for(i=1;i=b;i++) (2)t=t%1000; 3.请编写函数fun,它的功能是计算下列级数和,和值由函数值返回。 例如,当m=10,x=0.5时,函数值为1.648721。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include math.h double fun(double x,int m) { } main() { int i; FILE *out; printf(%f\n,fun(0.5,10)); out=(outfile.dat,w); for(i=0;i10;i++) fprintf(out,%f\n,fun((i+4)/ 10.0,10)); fclose(out); } 【答案及难度指数】★★ double f=1.0 ,p=1.0; //初始化 int i,j,t; for(i=1;i=m;i++) { t=1; for(j=1;j=i;j++) t=t*j; //计算分母,阶乘 p=p*x; //计算分子 f=f+p/t; //求解多项式 } return f; 95 1.请补充函数fun,该函数的功能是建立一个带头结点的单向链表并输出到文件file.dat和屏幕上,各结点的值为对应的下标,链表的结点数及输出的文件名作为参数传入。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # includestdio.h # includestdlib.h typedef struct s { int data; struct s *next; }NODE; void fun(int n,char *filename) { NODE *h,*p,*s ; FILE *f; int i; h=p=(NODE *)malloc(sizeof(NODE)); h-data=0; for(i=1;in;i++) { s=(NODE *)malloc(sizeof(NODE)); s-___1___; ___2___; p=___3___; } p-next=NULL; if((f=(filename,w))==NULL) { printf(Can not open file.dat!); exit(0); } p=h; fprintf(f,THE LIST\n); printf(THE LIST\n); while(p) { fprintf(f,%3d,p-data); printf(%3d,p-data); if(p-next!=NULL) { fprintf(f,-); printf(-); } p=p-next; } fprintf(f,\n); printf(\n); fclose(f); p=h; while(p) { s=p; p=p-next; free(s); } } main() { char *filename=file.dat; int n; printf(\nPlease n:); scanf(%d,n); fun(n,filename); } 【答案及难度指数】★★★★ (1)data=i (2)p-next=s (3)p-next 2.下列给定程序中,函数fun的功能是:从2个红球、4个白球、6个黑球中任意取出5个作为一组,进行输出。在每组中,可以没有黑球,但必须要有红球和白球。组合数作为函数值返回,正确的组合数应该是7。程序中a的值代表红球数,b的值代表白球数,c的值代表黑球数。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h int fun() { int a,b,c,sum=0; printf(\nThe result :\n\n); /******error*********/ for(a=0;a=2;a++) for(b=1;b=4;b++) { c=5-a-b; /******error********/ if(c=1 c=6) { sum=sum+1; printf(red:%4d white:%4d black:%4d\n,a,b,c); } } return sum; } main() { int sum; sum=fun(); printf(sum=%4d\n\n,sum); } 【答案及难度指数】★★★ (1)for(a=1;a=2;a++) (2)if(c=0 c=6) 3.请编写函数fun,该函数的功能是:将M行N列的二维数组中的数据,按列的顺序依次放到一维数组中。一维数组中数据的个数存放在形参n所指的存储单元中。 例如,若二维数组中的数据为: 1 1 1 1 2 2 2 2 3 3 3 3 则一维数组中的内容应是: 1 2 3 1 2 3 1 2 3 1 2 3 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h void fun(int (*str)[10],int *a,int *n,int mm,int nn) { } main() { int m[10][10]={{1,1,1,1},{2,2,2, 2},{3,3,3,3}},i,j ; int s[100]={0},n=0 ; FILE *out; printf(The matrix:\n) ; for(i=0 ;i3 ;i++) { for(j=0 ;j4 ;j++) printf(%3d,m[i][j]) ; printf(\n) ; } fun(m,s,n,3,4) ; out= (outfile.dat,w); printf(The array:\n) ; for(i=0 ;in ;i++) { printf(%3d,s[i]); fprintf(out,%d\n,s[i]); } printf(\n\n) ; fclose (out); 【答案及难度指数】★★★★ int i,j; for(j=0;jnn;j++) for(i=0;imm;i++) { a[*n]=*(*(str+i)+j); *n=*n+1; } 94 1.给定程序的功能是求出能整除n且不是偶数的各整数,并放在数组a中,这些除数的个数由m返回。例如,若n的值为12,则有2个数符合要求,它们是1、3。 请勿改动主函数main与其他函数中的任何内容,仅在横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h void fun(int a,int p[],int *m) { int i,j=0; for(i=1;i=a;i+=2) if((a%i)==0) p[j++]=___1___; *m=___2___; } main() { int n,a[1000],m,i; printf(\nPlease enter an integer number:\n); scanf(%d,n); fun(n,___3___); for(i=0;im;i++) printf(%d ,a[i]); printf(\n); } 【答案及难度指数】★★★★ (1)i (2)j (3)a,m 2.数列中,第一项值为3,后一项都比前一项的值增5。下列给定程序中,函数fun的功能是:计算前n(4n50)项的累加和;在累加过程中把那些被4除后余2的当前累加值放入数组中,符合此条件的累加值的个数作为函数值返回主函数。例如,当n的值为10时,符合此条件的累加值应为42、126。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # define M 10 int fun(int n,int *b) { /********error*******/ int i,j,k,sum; sum=0; for(k=3,i=0;in;i++,k+=5) { sum=sum+k; /********error********/ if(sum%4=2) b[j++]=sum; } return j; } main() { int b[M],m,n,i; printf(\nEnter n (4n=50): ); scanf(%d,n); m=fun(n,b); printf(\n\nThe result :\n); for(i=0;im;i++) printf(%6d,b[i]); printf(\n\n); } 【答案及难度指数】★★ (1)int i,j=0,k,sum; (2)if(sum%4==2) 3.请编写函数fun,该函数的功能是:将M行N列的二维数组中的数据,按行的顺序依次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。 例如,若二维数组中的数据为: 1 1 1 1 2 2 2 2 3 3 3 3 则一维数组中的数据应是: 1 1 1 1 2 2 2 2 3 3 3 3 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h void fun(int (*str)[10],int *c,int *n,int m,int t) { } main() { int matrix[10][10]={{1,1,1,1},{2, 2,2,2},{3,3,3,3}},i,j; int a[100]={0},n=0; FILE *out ; printf(The matrix:\n); for(i=0 ;i3 ;i++) { for(j=0 ;j4 ;j++) printf(%3d,matrix[i][j]); printf(\n); } fun(matrix,a,n,3,4) ; printf(The A array:\n) ; out= (outfile.dat,w); for(i=0 ;in ;i++) { printf(%3d,a[i]); fprintf(out,%d\n,a[i]); } fclose (out); printf(\n\n); } 【答案及难度指数】★★★★ int i,j; for(i=0;im;i++) for(j=0;jt;j++) { c[*n]=*(*(str+i)+j); *n=*n+1; } 93 1.给定程序的功能是求出能整除n且不是偶数的各整数,并放在数组a中,这些除数的个数由m返回。例如,若n的值为12,则有2个数符合要求,它们是1、3。 请勿改动主函数main与其他函数中的任何内容,仅在横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h void fun(int a,int p[],int *m) { int i,j=0; for(i=1;i=a;i+=2) if((a%i)==0) p[j++]=___1___; *m=___2___; } main() { int n,a[1000],m,i; printf(\nPlease enter an integer number:\n); scanf(%d,n); fun(n,___3___); for(i=0;im;i++) printf(%d ,a[i]); printf(\n); } 【答案及难度指数】★★★★ (1)i (2)j (3)a,m 2.数列中,第一项值为3,后一项都比前一项的值增5。下列给定程序中,函数fun的功能是:计算前n(4n50)项的累加和;在累加过程中把那些被4除后余2的当前累加值放入数组中,符合此条件的累加值的个数作为函数值返回主函数。例如,当n的值为10时,符合此条件的累加值应为42、126。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # define M 10 int fun(int n,int *b) { /********error*******/ int i,j,k,sum; sum=0; for(k=3,i=0;in;i++,k+=5) { sum=sum+k; /********error********/ if(sum%4=2) b[j++]=sum; } return j; } main() { int b[M],m,n,i; printf(\nEnter n (4n=50): ); scanf(%d,n); m=fun(n,b); printf(\n\nThe result :\n); for(i=0;im;i++) printf(%6d,b[i]); printf(\n\n); } 【答案及难度指数】★★ (1)int i,j=0,k,sum; (2)if(sum%4==2) 3.请编写函数fun,该函数的功能是:将M行N列的二维数组中的数据,按行的顺序依次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。 例如,若二维数组中的数据为: 1 1 1 1 2 2 2 2 3 3 3 3 则一维数组中的数据应是: 1 1 1 1 2 2 2 2 3 3 3 3 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h void fun(int (*str)[10],int *c,int *n,int m,int t) { } main() { int matrix[10][10]={{1,1,1,1},{2, 2,2,2},{3,3,3,3}},i,j; int a[100]={0},n=0; FILE *out ; printf(The matrix:\n); for(i=0 ;i3 ;i++) { for(j=0 ;j4 ;j++) printf(%3d,matrix[i][j]); printf(\n); } fun(matrix,a,n,3,4) ; printf(The A array:\n) ; out= (outfile.dat,w); for(i=0 ;in ;i++) { printf(%3d,a[i]); fprintf(out,%d\n,a[i]); } fclose (out); printf(\n\n); } 【答案及难度指数】★★★★ int i,j; for(i=0;im;i++) for(j=0;jt;j++) { c[*n]=*(*(str+i)+j); *n=*n+1; } 92 1.给定程序中,函数fun的功能是:把形参str所指字符串中下标为奇数的字符右移到下一个奇数位置,最右边被移出字符串的字符绕回放到第一个奇数位置,下标为偶数的字符不动(注意:字符串的长度大于等于2)。 例如,形参str所指的字符串为:123456,执行结果为:163254。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h void fun(char *str) { int i,n,j; char c; n=0; for(i=0;str[i]!=‘\0’;i++) n++; if(n%2==0) j=n-___1___; else j=n-2; c=___2___; for(i=j-2;i=1;i=i-2) str[i+2]=str[i]; str[1]=___3___; } main() { char str[100]=123456; printf(\nThe original string is : %s\n,str); fun(str); printf(\nThe result is : %s\n,str); } 【答案及难度指数】★★★★ (1)1 (2)str[j] (3)c 2.下列给定程序中,函数fun的功能是:求f的值,设: 例如,当n为10时,函数值应为1.025347。 请修改程序中的错误,使程序能输出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include math.h /*******error*********/ fun(int n) { int k; double f,t,p,q; k=1; f=1.0; while(k=n) { t=2.0*n; p=t-1.0; q=t+1.0; f=f*t*t/p/q; k++; } /*******error********/ return f } main() { printf(%lf\n,fun(10)); } 【答案及难度指数】★★ (1)double fun(int n) (2)return f; 3.假定输入的字符串中只包含字母和#号,请编写函数fun,它的功能是:只删除字符串前导和尾部的#号,串中字母之间的#号都不删除。形参n给出了字符串的长度,形参j给出了字符串中前导#号的个数,形参k给出了字符串中最后#号的个数。在编写函数时,不得使用C语言提供的字符串函数。 例如,若字符串中的请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # include string.h void fun(char *a,int n,int j,int k) { } main() { char str[81],*s,*st; int m=0,t=0,h=0; FILE *out; printf(Enter a string:\n); gets(str); s=st=str; while(*s) { s++; m++; } s--; while(*s==‘#’) { s--; t++; } while(*st==‘#’) { st++; h++; } fun(str,m,h,t); printf(The string after deleted:\n); puts(str); out= (outfile.dat,w); strcpy(str,#####A#BC#DE#F#######); fun(str,strlen(str),5,7); fprintf(out,%s,str); fclose (out); 【答案及难度指数】★★★★ int i=0; char *p; for(p=a+j;pa+n-k;p++) //确定执行字符移动的循环条件 { *(a+i)=*p; //用第一个非#号字符特代#字符 i++; } *(a+i)=‘\0’; //在新生成的字符串加尾符 91 1.数组s全由字母字符组成,请补充fun函数,该函数的功能是:请把s中的字母转换成紧接着的下一个字母,如果原来的字母为a或A,则相应地转换成b或B,结果仍保存在原数组中。 例如,输入aAZut,则输出bBAvu。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 100 void fun(char p[]) { int j; for(j=0;___1___;j++) if(p[j]==‘z’ || p[j]==‘Z’) p[j]-=___2___; else p[j]+=___3___; } main() { char s[N]; printf(Please a string: \n); gets(s); printf(The original string\n); puts(s); fun(s); printf(The new string \n); puts(s); } 【答案及难度指数】★★★ (1)p[j]!=‘\0’ (2)25 (3)1 2.下列给定程序中,函数fun的功能是:从整数1到50之间,选出能被3整除且有一位上的数是5的数,并把这些数放在b所指的数组中,这些数的个数作为函数值返回。规定,函数中a1放个位数,a2放十位数。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h /********error********/ int fun(int *b); { int j,a1,a2,i=0; /*******error*********/ for(j=10;j=50;j++) { a2=j/10; a1=j-a2*10; if((j%3==0 a2==5) || (j%3==0 a1==5)) { b[i]=j; i++; } } /*******error********/ return j; } main() { int a[50],i,n; n=fun(a); printf(The result is:\n); for(i=0;in;i++) printf(%4d,a[i]); printf(\n); } 【答案及难度指数】★★★★ (1)int fun(int *b) (2)for(j=1;j=50;j++) (3)return i; 3.请编写函数fun,其功能是:计算并输出3到m之间所有素数的平方根之和。 例如,若主函数从键盘给m输入50后,则输出为s=63.665791。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若 干语句。 注意:m的值要大于2但不大于100。部分源程序给出如下。 # include math.h # include stdio.h double fun(int m) { } main() { int m; double s; FILE *out; printf(\n\n m: ); scanf(%d,m); s=fun(m); printf(\n\ns=%f\n\n,s); out=(outfile.dat,w); for(m=0;m10;m++) fprintf(out,%f\n,fun(m+80)); fclose(out); } 【答案及难度指数】★★★ int n,k,i; double sum=0.0; for(n=3;n=m;n++) //判断n是否为素数 { k=sqrt(n); //求n平方根 for(i=2;i=k;i++) if(n%i==0) break; //如果n不是素数,跳出 if(i=k+1) sum+=sqrt(n); //求平方根的和 } return sum; 90 1.给定程序的功能是将未在字符串s1中出现,而在字符串s2中出现的字符,形成一个新的字符串放在s中,s中字符按原字符串中字符顺序排序,但去掉重复字符。 例如,当s1=12345,s2=24677时,s中的字符为:67。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h void fun(char *s1,char *s2,char *s) { int i,j,n1,n2,k,n=0; n1=strlen(s1); n2=strlen(s2); for(i=0;in1;i++) { for(j=0;jn1;j++) if(s2[i]==s1[j]) break; if(j=n2) { for(k=0;kn;k++) if(s2[i]==s[k]) ___1___; if(k=n) s[n++]=___2___; } } ___3___; } main() { char s1[100],s2[100],s[100]; printf(\nPlease enter string s1:); scanf(%s,s1); printf(\nPlease enter string s2:); scanf(%s,s2); fun(s1,s2,s); printf(The result is: %s\n,s); } 【答案及难度指数】★★★ (1)break (2)s2[i] (3)s[n]=‘\0’ 2.下列给出程序中,函数fun的功能是:根据形参n的值(2≤n≤9),在n行n列的二维数组中存放如下所示的数据,由main()函数输出。 例如,若输入3,则输出: 1 2 3 2 4 6 3 6 9 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include conio.h # define N 10 int b[N][N]={0}; /******error*********/ fun(int **b,int n) { int j,k; for(j=0;jn;j++) for(k=0;kn;k++) /*******error*********/ b[j][k]=k*j; } main() { int i,j,n; printf( Enter n:); scanf(%d,n); fun(b,n); for(i=0;in;i++) { for(j=0;jn;j++) printf(%4d,b[i][j]); printf(\n); } } 【答案及难度指数】★★★★ (1)fun(int (*b)[N],int n) (2)b[j][k]=(k+1)*(j+1); 3.假定输入的字符串中只包含字母和#号,请编写函数fun,它的功能是:使字符串的前导#号不得多于m个;若多于m个,则删除多余的#号;若少于或等于m个,则什么也不做,字符串中间和尾部的#号不删除。 例如,若字符串中的内容为####adfb##dfs####,设m的值为2,删除后,字符串中的内容则应当是##adfb##dfs####;若m的值为4,则字符串中的内容仍为####adfb##dfs####。m的值在主函数中输入。在编写函数时,不得使用C语言提供的字符串函数。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h void fun(char *s,int m) { } main() { char str[100]; int m; FILE *out; printf(Enter a string:\n); gets (str); printf(Enter m: ); scanf (%d,m); fun(str,m); printf(The string after deleted:\n); puts(str); out=(outfile.dat,w); strcpy(str,######asdf##dfs###dsfs); fun(str,4); fprintf(out,%s,str); fclose(out); } 【答案及难度指数】★★★ int i=0,k=0; char *t=s; while(*t==‘#’) { k++; t++; } t=s; if(km) t=s+k-m; while(*t) { s[i]=*t; i++; t++; } s[i]=‘\0’; 89 1.给定程序的功能是计算以下的公式的值: S=f(-n)+f(-n+1)+…+f(0)+f(1)+f(2)+…+f(n) 例如,当n为5时,函数值应为:10.407143。 请勿改动主函数main中的任何内容,仅在f函数和fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include math.h double f(double x) { if(fabs(x-0.0)1e-6 || fabs(x-2.0)1e-6) return ___1___; else if(x0.0) return (x-1)/(x-2); else return (x+1)/(x-2); } double fun(int n) { int i; double s=0.0,y; for(i=-n;___2___;i++) { y=f(1.0*i); s+=y; } return ___3___; } main() { printf(the result is :%lf\n,fun(5)); } 【答案及难度指数】★★★ (1)0.0 (2)i=n (3)s 2.下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数fun的作用是求出单向链表结点(不包括头结点)数据域中的最大值,并且作为函数值返回。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include conio.h # include stdlib.h typedef struct a { int data; struct a *next; } NODE; fun(NODE *h) { int max=-1; NODE *p; /*******error*********/ p=h; while(p) { if(p-datamax) max=p-data; /*******error*********/ p=h-next; } return max; } printresult(int s,FILE *pf) { fprintf(pf,\nThe max in link : %d\n,s); } NODE *link(int n,int m) { NODE *h,*p,*s; int i; h=p=(NODE*)malloc(sizeof(NODE)); h-data=9999; for(i=1;i=n;i++) { s=(NODE*)malloc(sizeof(NODE)); s-data=rand()%m; s-next=p-next; p-next=s; p=p-next; } p-next=NULL; return h; } printlink(NODE *h,FILE *pf) { NODE *p; p=h-next; fprintf(pf,\nTHE LIST:\n\n HEAD); while(p) { fprintf(pf,-%d ,p-data); p=p-next; } fprintf(pf,\n); } main() { NODE *head; int m; head=link(12,100); printlink(head,stdout); m=fun(head); printf(\nTHE RESULT :\n); printresult(m,stdout); } 【答案及难度指数】★★★★ (1)p=h-next; (2)p=p-next; 3.规定输入的字符串中只含字母和#号。请编写函数fun,它的功能是:将字符串中的前导#号全部删除,中间和尾部的#号不删除。 例如,若字符串中的内容为#####a#b##cd##ef####,删除后,字符串中的内容则应当是a#b##cd##ef####。在编写函数时,不得使用C语言提供的字符串函数。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # include string.h void fun(char *s) { } main() { char str[100]; FILE *out; printf(Enter a string :\n); gets(str); fun(str); printf(The string after deleted :\n); puts(str); out=(outfile.dat,w); strcpy(str,####adf##ef##); fun(str); fprintf(out,%s,str); fclose(out); } 【答案及难度指数】★★★ int i=0; char *p=s; while(*p*p==‘#’) p++; while(*p) { s[i]=*p; i++; p++; } s[i]=‘\0’; 88 1.请补充main函数,该函数的功能是:把字符串s中的字符向前移动一位,原来的第一个字符移动到字符串尾,结果仍然保存在原字符串中。 例如,输入Welcome!,则结果输出elcome!W。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何注意:部分源程序给出如下。 # include stdio.h # define N 80 main() { char s[N],ch; int i; printf(Please a string: \n); gets(s); printf(The original string \n); puts(s); ch=s[0]; for(i=0;___1___;i++) s[i]=s[i+1]; ___2___; printf(The new string \n); puts(s); } 【答案及难度指数】★★★ (1)s[i+1] (2)s[i]=ch 2.下列给定程序中的函数link的功能是:创建带头结点的单向链表,并为各结点数据域赋0到max-1的值。 请修改函数link中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include conio.h # include stdlib.h typedef struct a { int data; struct a *next; } NODE; NODE *link(int n,int max) { NODE *h=NULL,*p,*s; int i; s=(NODE*)malloc(sizeof(NODE)); h=s; /******error**********/ ___填空____ for(i=1;in;i++) { s=(NODE*)malloc(sizeof(NODE)); /*******error*********/ s-data=rand()%max; s-next=p-next; p-next=s; p=p-next; } s-next=NULL; /********error********/ return p; } printlink(NODE *h) { NODE *p; p=h-next; printf(\n\nTHE LIST :\n\n HEAD); while(p) { printf(-%d ,p-data); p=p-next; } printf(\n); } main() { NODE *head; head=link(10,20); printlink(head); } 【答案及难度指数】★★★★ (1)p=s; (2)s-data=rand()%(max-1); (3)return h; 3.假定输入的字符串中只包含字母和#号,请编写函数fun,它的功能是:除了字符串前导的#号之外,将串中其他#号全部删除。在编写函数时,不得使用C语言提供的字符串函数。 例如,若字符串中的内容为####as#df##ds#af####,删除后,字符串中的内容则应当是####asdfdsaf。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include string.h # include stdio.h # include conio.h void fun(char *s) { } main() { char str[100]; FILE *out; printf(Enter a string :\n); gets(str); fun(str); printf(The string after deleted:\n); puts(str); out= (outfile.dat,w); strcpy(str,##asdf##df#s##); fun(str); fprintf(out,%s,str); fclose (out); } 【答案及难度指数】★★★ int i=0; char *p=s; while(*p*p==‘#’) { s[i]=*p; i++; p++; } while(*p) { if(*p!=‘#’) { s[i]=*p; i++; } p++; } s[i]=‘\0’; 87 1.人员的记录由编号和出生年、月、日组成,N名人员的数据已在主函数中存入结构体数组student中,且编号唯一。函数fun的功能是:找出指定编号人员的数据,作为函数值返回,由主函数输出,若指定编号不存在,返回数据中的编号为空串。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # define N 8 typedef struct { char num[10]; int year,month,day; } STUDENT; ___1___ fun(STUDENT *student,char *num) { int i; STUDENT a={000003,1979,9,1}; for(i=0;iN;i++) if(strcmp(___2___,num)==0) return (___3___); return a; } main() { STUDENT student[N]= { {000001,1978,2,15},{000002, 1981,9,21},{000003,1979,9,1},{000004,1982,7,15},{000005,1980,9,28},{000006,1983,11,15},{000007,1983,6,22},{000008,1984,8,19} }; STUDENT s; char n[10]=666666; s=fun(student,n); if(s.num[0]==0) { printf(\nNot found!\n); } else { printf(\nSucceed!\n ); printf(%s %d-%d-%d\n,s.num, s.year,s.month,s.day); } } 【答案及难度指数】★★★ (1)STUDENT (2)student[i].num (3)student[i] 2.下列给定程序中,函数fun的功能是:找出100至n(不大于500)之间三个位上的数字都相等的所有整数,把这些整数放在str所指数组中,个数作为函数值返回。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # define N 100 int fun(int *str,int n) { int i,j,k,x,y,z; j=0; for(i=100;in;i++) { /********error********/ k=n; x=k%10; k/=10; /********error********/ y=k/10; z=k/10; if(x==y x==z) str[j++]=i; } return j; } main() { int b[N],n,a=0,i; do { printf(\nEnter n(500n100): ); scanf(%d,n); } while(n500); a=fun(b,n); printf(\n\nThe result :\n); for(i=0;ia;i++) printf(%5d,b[i]); printf(\n\n); } 【答案及难度指数】★★★ (1)k=i; (2)y=k%10; 3. 编写一个函数,该函数可以统计一个长度为3的字符串在另一个字符串中出现的次数。 例如,输入的字符串为asd asasdfg asd as zx67 asd mklo,子字符串为asd,则应输出4。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若 干语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # include conio.h int fun(char *s,char *s1) { } main() { char s[81],s1[4]; int n; FILE *out; printf( main string: ); gets(s); printf( sub string: ); gets(s1); puts(s); puts(s1); n=fun(s,s1); printf(n=%d\n,n); out= (outfile.dat,w); strcpy(s,asd asasdfg asd as zx67 asd mklo); strcpy(s1,as); fprintf(out,%d,fun(s,s1)); fclose (out); } 【答案及难度指数】★★★★ int n; char *p ,*r; n=0; while(*s) { p=s; r=s1; while(*r) if(*r==*p) //判断p和r指向的字符是否相同 { r++; p++; } else break; if(*r==‘\0’) //如果r指向串的尾标志,则统计n加1 n++; s++; } return n; 86 1.请补充fun函数,该函数的功能是:把字符的ASCII码为奇数的字符从字符串str中删除,结果仍然保存在字符串str中。字符串str从键盘输入,其长度作为参数传入fun函数。 例如,输入abcdef,则输出bdf。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 100 void ___1___ { int i,j; ___2___; for(i=0;in;i++) if(s[i]%2==0) s[j++]=s[i]; ___3___; } main() { int i=0,len=0; char str[N]; printf(Please a string:\n); gets(str); while(str[i]!=‘\0’) { len++; i++; } fun(str,len); printf(The result string :\n); puts(str); } 【答案及难度指数】★★★ (1)fun(char s[],int n) (2)j=0 (3)s[j]=‘\0’ 2.下列给定程序中,函数fun的功能是:计算函数F(x,y,z)=(x+v)/(x-y)+(z+y)/(z-y)的值。其中x和y的值不等,z和y的值不相等。例如,当x的值为1,y的值为2,z的值为3时,函数值为2.00。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include stdlib.h /*******error*********/ # define F(m,n) (m/n) float fun(float a,float b,float c) { float s; s=F((a+b),(a-b))+F((c+b),(c-b)); /******error**********/ Return (s); } main() { float x,y,z,sum; printf( x y z: ); scanf(%f%f%f,x,y,z); printf(x=%f,y=%f,z=%f\n,x,y,z); if(x==y || y==z) { printf(Data error!\n); exit(0); } sum=fun(x,y,z); printf(The result is :%5.2f\n,sum); } 【答案及难度指数】★★★ (1)#define F(m,n) (m)/(n) (2)return (s); 3.编写一个函数,从传入的num个字符串中找出最短的一个字符串,传回该串地址(用*作为结束输入的标志)。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # include conio.h char *fun(char (*s)[100],int num) { } main() { char str[10][100],*min; int n,i=0; FILE *out; printf( strings with ‘*’ as end:); gets(str[i]); puts(str[i]); while(!strcmp(str[i],*)==0) { i++; gets(str[i]); puts(str[i]); } n=i; min=fun(str,n); printf(\nmin=%s\n,min); out= (outfile.dat,w); strcpy(str[0],just,); strcpy(str[1],a); strcpy(str[2],test); strcpy(str[3],some); strcpy(str[4],too?!?); fprintf(out,%s,fun(str,5)); fclose (out); } 【答案及难度指数】★★★★ int i; char *min; min=s[0]; //min初始化 for(i=0;inum;i++) if(strlen(min)strlen(s[i])) //min指向的字符串与其他的字符串长度进行比较 min=s[i]; return min; //返回最小值的字符串 85 1.给定程序功能是用选择排序法对6个字符串进行排序。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # define LEN 20 fun(char *str[6]) { int i,j; char *p; for(i=0;i5;i++) for(j=i+1;j6;j++) if(strcmp(*(str+i),___1___)0) { p=*(str+i); str[i]=___2___; *(str+j)=___3___; } } main() { int i; char *str[6],s[6][LEN]; for(i=0;i6;i++) str[i]=s[i]; printf(Enter 6 string(1 string at each line): \n); for(i=0;i6;i++) scanf(%s,str[i]); fun(str); printf(The strings after sorting:\n); for(i=0;i6;i++) printf(%s\n,str[i]); } 【答案及难度指数】★★★ *(str+j) (2)str[j] (3)p 2.下列给定程序中,函数fun的功能是:计算并输出下列数的前m项之和SN,直到SN+1大于p为止,p的值通过形参传入。 例如,若p的值为10.0,则函数值为9.592857。 请修改程序中的错误,使程序能输出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h double fun(double p) { int m; double s,t; m=2; s=2.0; while(s=p) { t=s; /*******error********/ s=s+(m+1)/m; m++; } printf(n=%d\n,m); /*******error********/ return s; } main() { printf(%f\n,fun(10)); } 【答案及难度指数】★★★ s=s+(double)(m+1)/m; (2)return t; 3.下列程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int b[][M],int n),该函数的功能是:使数组右上半三角元素中的值乘以n。 例如,若n的值为2,b数组中的值为: 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # include stdlib.h # include string.h # define M 5 void fun(int b[][M],int n) { } main () { int b[M][M],n,i,j; FILE *out; printf(The array\n); for(i=0;iM;i++) { for(j=0;jM;j++) { b[i][j]=rand()%20; printf(%4d,b[i][j]); } printf(\n); } n=rand()%4 ; printf(n=%4d\n,n); fun(b,n); printf( THE RESULT\n); for(i=0;iM;i++) { for(j=0;jM;j++) printf(%4d,b[i][j]); printf(\n); } out= (outfile.dat,w); for(i=0;iM;i++) for(j=0;jM;j++) b[i][j]=i*j; fun(b,6); for(i=0;iM;i++) { for(j=0;jM;j++) fprintf(out,%4d,b[i][j]); fprintf(out,\n); } fclose (out); } 【答案及难度指数】★★★★ int i,j; for(j=0;jM;j++) //列循环 for(i=0;i=j;i++) //行小于列的行循环 b[i][j]=b[i][j]*n; //右上角元素乘以n 84 1.请补充main函数,该函数的功能是:从键盘输入两个字符串并分别保存在字符数组s1和s2中,用字符串s2替换字符串s1前面的所有字符,注意:s2的长度不大于s1,否则需要重新输入。 例如,如果输入s1=cdef,s2=aa,则输出aaef。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何注意:部分源程序给出如下。 # include stdio.h # include string.h main() { char s1[81],s2[81]; char *p1=s1,*p2=s2; do { printf(Please the first string s1\n); gets(s1); printf(Please the second string s2 \n); gets(s2); } while(strlen(s1)___1___strlen(s2)); while(___2___) *p1++=*p2++; printf(The result s1 is\n); puts(___3___); } 【答案及难度指数】★★★ (2)*p2 (3)s1 2.下列给定程序中,函数fun的功能是用下面的公式π的近似值,直到最后一项的绝对值小于指定的数(参数r)为止: 例如,程序运行后,输入0.0001,则程序输出3.1414。 请修改程序中的错误,使它能输出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include math.h # include stdio.h float fun(float r) { int s; float n,t,pi; t=1; pi=0; n=1; s=1; /*******error********/ while(t=r) { pi=pi+t; n=n+2; s=-s; /*******error*********/ t=s%n; } pi=pi*4; return pi; } main() { float x1,x2; printf(Enter a float number: ); scanf(%f,x1); x2=fun(x1); printf(%6.4f\n,x2); } 【答案及难度指数】★★★ (1)while(fabs(t)=r) (2)t=s/n; 3.请编写函数fun,该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。 例如,若二维数组中的数据为: * * * * @ @ @ @ # # # # 则字符串中的内容应是:*@#*@#*@#。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # define M 3 # define N 4 void fun(char (*a)[N],char *c) { } main() { char s[100],str[M][N]={{‘*’,’*’, ‘*’,’*’},{‘@’,’@’,’@’,’@’},{‘#’,’#’,’#’,’#’}}; int i,j; FILE *out; printf(The matrix:\n); for(i=0;iM;i++) { for(j=0;jN;j++) printf(%3c,str[i][j]); printf(\n); } fun(str,s); printf(The A string:\n); puts(s); printf(\n\n); out= (outfile.dat,w); fprintf(out,%s,s); fclose (out); } 【答案及难度指数】★★★★ int i,j,k=0; for(j=0;jN;j++) //列循环 for(i=0;iM;i++) //行循环 { c[k]=*(*(a+i)+j); //将每一个元素赋值到一维数组c k++; //指向下一数组元素 } c[k]=‘\0’; //数组结束 83 1.请补充main函数,该函数的功能是:从键盘输入若干字符放到一个字符数组中,当按回车键时结束输入,最后输出这个字符数组中的所有字符。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何注意:部分源程序给出如下。 # include stdio.h # include ctype.h main() { int i=0; char str[81]; char *p=str; printf( a string \n); for(i=0;i100;i++) { str[i]=getchar(); if(str[i]==‘\n’) ___1___; } str[i]=___2___; printf( The string is: \n); while(*p) putchar(___3___); } 【答案及难度指数】★★★ break (2)’\0’ (3)*p++ 2.下列给定程序中,函数fun的功能是:给一维数组b输入任意3个整数,并按如下的规律输出。 例如输入1、2、3,程序运行后将输出以下方阵: 3 1 2 2 3 1 1 2 3 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # define N 3 /*******error*******/ void fun(int b) { int i,j,k,n; printf(Enter 3 number : ); for(i=0;iN;i++) scanf(%d,b[i]); printf(\n\nThe result :\n\n); for(i=N;i0;i--) { k=b[N-1]; /******error*******/ for(j=N-1;j0;j--) b[j]=b[j+1]; b[0]=k; for(n=0;nN;n++) printf(%d ,b[n]); printf(\n); } } main() { int b[N]; fun(b); printf(\n\n); } 【答案及难度指数】★★★ (1)void fun(int b[N]) / void fun(int b[]) / void fun(int *b) (2)b[j]=b[j-1]; 3.请编写函数fun,它的功能是计算: F作为函数值返回。 在C语言中可调用log(n)函数求ln(n)。log函数的引用说明是:double log(double x)。 例如,若n的值为10,则fun函数值为3.886440。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include math.h # include stdio.h double fun(int n) { } main() { int i; FILE *out; printf(%f\n,fun(10)); out=(outfile.dat,w); for(i=0;i10;i++) fprintf(out,%f\n,fun(i+15)); fclose(out); } 【答案及难度指数】★★ int i; double f=0.0,log(double x);//调用log函数 for(i=1;i=n;i++) //在C语言中可调用log(n)函数求ln(n) f=f+log(i); f=sqrt(f); //利用C语言中的sqrt函数求平方根 return f; 【 82 1.请补充main函数,该函数的功能是:把一个二维字符数组每行字符串最大的字符拷贝到字符数组str中。 例如,如果s [4]={abt,aec,ghs,irt},则str=test。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何注意:部分源程序给出如下。 # include stdio.h main() { int i=0; char *s[4]={abt,aec,ghs,irt}; char **p; char str[4]; ___1___; for(i=0;i4;i++) { str[i]=*p[i]; while(*p[i]) { if(str[i]*p[i]) str[i]=*p[i]; ___2___; } } ___3___; printf(The new string \n); puts(str); } 【答案及难度指数】★★★ p=s (2)p[i]++ (3)str[i]=‘\0’ 2.下列给定程序中,函数fun的功能是:把主函数中输入的3个数,最大的放在x中,最小的放在z中。例如,输入的数为:1 2 3,输出结果应当是:x=3.0,y=2.0,z=1.0。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h void fun(float *p,float *q,float *s) { /****error******/ float *a; if(*p*q) { a=*p; *p=*q; *q=a; } /****error******/ if(*s*p) { a=*s; *s=*p; *p=a; } if(*q*s) { a=*q; *q=*s; *s=a; } } main() { float x,y,z; printf( x y z:); scanf(%f%f%f,x,y,z); printf(x=%4.1f,y=%4.1f,z=%4.1f \n\n,x,y,z); fun(x,y,z); printf(x=%4.1f,y=%4.1f,z=%4.1f \n\n,x,y,z); } 【答案及难度指数】★★★ (1)float a; (2)if(*s*p) 3.请编写函数fun,其功能是将两个两位数的正整数x、y合并成一个整数放在z中。合并的方式是:将x的十位和个位依次放在z的十位和千位上,y的十位和个位依次放在z的个位和百位上。 例如,当x=12,y=34,调用该函数后,z=2413。 请勿改动主函数main与其他函数中的任何注意:部分源程序给出如下。 # include stdio.h # define N 10 main() { int i,j; int n; int a[N]={1,2,3,4,5,6,7,11,15,16}; printf(Please n \n); scanf(%d,n); printf(\nn=%d ,n); printf(The original list is \n); for(i=0;iN;i++) printf(%4d ,a[i]); for(i=0;iN;i++) if(n=a[i]) { for(j=N;___1___;j--) ___2___; a[j]=n; ___3___; } if(i==N) a[i]=n; printf(The New list is: \n); for(i=0;iN+1;i++) printf(%4d ,a[i]); } 【答案及难度指数】★★★ ji (2)a[j]=a[j-1] (3)break 2.下列给定程序中,函数fun的功能是:将十进制正整数n转换成i(2≤i≤9)进制数,并按位输出。例如,若输入8和2,则应输出1000(即十进制数8转换成二进制表示是1000)。 请修改fun函数中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /********error*******/ void fun(int n,int i); { int a[20],j; for(j=0;n;j++) { /*******error********/ a [j]=n/i; n /=i; } for(;j;j--) /********error******/ printf(%d,a[j]); } main() { int x,num; printf(\nPlease enter a number and a base:\n); scanf(%d%d,num,x); fun(num,x); printf(\n); } 【答案及难度指数】★★★ (1)void fun(int n,int i) (2)a[j]=n%i; (3)printf(%d,a[j-1]); 3.请编写函数fun,其功能是计算并输出下列多项式值: 例如,若主函数从键盘给m输入8后,则输出为F=0.662872。 注意:m的值要求大于1但不大于100。 请勿改动主函数main与其他函数中的任何); scanf(%d,m); f=fun(m); printf(\ns=%f\n,f); out=(outfile.dat,w); for(m=5;m10;m++) fprintf(out,%f\n,fun(m)); fclose(out); } 【答案及难度指数】★★ int i; double fn=0.0; //初始化多项式求和的值 for(i=1;i=m;i++) fn+=(1.0/(2*i-1)-1.0/(2*i)); //多项式中的一项 return fn; 80 1.请补充main函数,该函数的功能是:输出一个N×N矩阵,要求周边元素赋值0,非周边元素赋值1。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何注意:部分源程序给出如下。 # include stdio.h # define N 10 main() { int a[N][N]; int i,j,n; printf(Please n:\n); scanf(%d,n); for(i=0;in;i++) for(j=0;jn;j++) { if(i==0||i==n-1||j==0||j==n-1) ___1___; else ___2___; } printf(The result is:\n); for(i=0;in;i++) { printf(\n); for(j=0;jn;j++) printf(%4d,a[i][j]); } } 【答案及难度指数】★★★ a[i][j]=0 (2)a[i][j]=1 2.下列给定程序中,函数fun的功能是:交换主函数中两个变量的值。例如,若变量x中的值为1,y中的值为2,则程序运行后x中的值为2,y中的值为1。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h /****error******/ void fun(int a,int b) { int t; /****error******/ t=a;a=b;b=t; } main() { int x,y; x=1; y=2; fun(x,y); printf(the result is %d,%d\n,x,y); } 【答案及难度指数】★★★ (1)void fun(int *a,int *b) (2)t=*a;*a=*b;*b=t; 3.学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组stu中,请编写函数fun,它的功能是:把小于等于平均分的学生数据放在l所指的数组中,大于等于平均分的学生人数通过形参n传回,平均分通过函数值返回。 请勿改动主函数main与其他函数中的任何 SCORE low [M],t; FILE *out ; int i,j,n; double ave; ave=fun(stu,low,n); printf(The %d student data which is lower than %7.3f:\n,n,ave); for(i=0;in;i++) printf(%s %4.1f\n,low[i].num, low[i].s); printf(\n); out=(outfile.dat,w); fprintf(out,%d\n%7.3f\n,n,ave); for(i=0;in-1;i++) for(j=i+1;jn;j++) if(low[i].slow[j].s) { t=low[i] ; low[i]=low[j]; low[j]=t; } for(i=0;in;i++) fprintf(out,%4.1f\n,low[i].s); fclose(out); } 【答案及难度指数】★★ double aver=0.0; //放平均分的变量设置初始化 int i,j=0; for(i=0;iM;i++) //求总和 aver+=c[i].s; aver/=M; //求平均分 for(i=0;iM;i++) //循环判断每一个成绩与平均分的关系 if(c[i].s=aver) //如果成绩小于等于平均分 { *(l+j)=c[i]; //将小于等于平均分的成绩存入l j++; } *n=j; //将小于平均分的个数j赋值给n return aver; //返回平均分 79 1.已知学生的记录由学号和学习成绩组成,N名学生的数据已存入student结构体中,给定程序的功能是找出成绩最高的学生记录,通过形参返回主函数。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # define N 10 typedef struct s { char num[10]; int s; } student; fun(student STU[],student *s) { ___1___ a; int i; a=STU[0]; for(i=1;iN;i++) if(STU[i].sa.s) ___2___=STU[i]; *s=___3___; } main() { student STU[N]= { {01,81},{02,89},{03,66}, {04,87},{05,77},{06,90},{07,79},{08,61},{09,80},{10,71} },m; int i; printf(The original data\n); for(i=0;iN;i++) printf(No=%s Mark=%d\n,STU[i]. num,STU[i].s); fun(STU,m); printf(The highst : %s,%d\n,m.num, m.s); } 【答案及难度指数】★★★ student (2)a (3)a 2.下列给定程序中,函数fun的功能是:计算整数m的阶乘。 请修改程序中的错误或在横线处填上适当的注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h double fun(int m) { double result=1.0; /****error******/ while(m1 m100) result*=--m; /****error******/ ___填 空___ } main() { int m; printf(Enter an integer 100: ); scanf(%d,m); printf(\n\n%d!=%1g\n\n,m,fun(m)); } 【答案及难度指数】★★★ result*=m--; (2)return result; 3.请编写函数fun,其功能是:将两个丙位数的正整数x、y合并成一个整数放在z中。合并的方式是:将x的十位和个位依次放在z的千位和十位上,y的十位和个位依次放在z的个位和百位上。 例如,当x=12,y=34,调用该函数后,z=1423。 请勿改动主函数main与其他函数中的任何%ld\n,z); out= (outfile.dat,w); for(x=0;x10;x++) { fun(x+44,x+55,z); fprintf(out,%ld\n,z); } fclose (out); } 【答案及难度指数】★★ *z=(x/10)*1000+(x%10)*10+(y%10)*100+y/10; 78 1.请补充main函数,该函数的功能是:计算每个学生科目的平均分,并把结果保存在数组a中。 例如,当score[N][M]={ {89,78,90,71,61},{78.5,84,83,65,63},{88,91.5,89,93,95},{72.5,65,56,75,77}}时,四个学生的平均分为:77.8 74.7 91.3 69.1。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # define N 4 # define M 5 main() { int i,j; static float score[N][M]= { {89,78,90,71,61}, {78.5,84,83,65,63}, {88,91.5,89,93,95}, {72.5,65,56,75,77} }; float a[N]; for(i=0;iN;i++) ___1__; for(i=0;iN;i++) { for(j=0;jM;j++) ___2___; a[i]/=M; } for(i=0;iN;i++) printf(\n Student%d\taverage= %5.1f,i+1,a[i]); } 【答案及难度指数】★★★ a[i]=0 (2)a[i]+=score[i][j]; 2.下列给定程序中函数fun的功能是:先将在字符串str中的字符按正序存放到s串中,然后把str中的字符按逆序连接到s串的后面。例如,当str中的字符串为asd时,则s中的字符串应为asddsa。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h void fun(char *str,char *s) { int i,s1; s1=strlen(str); /*******error*********/ for(i=0;i=s1;i++) s[i]=str[i]; for(i=0;is1;i++) s[s1+i]=str[s1-i-1]; /********error********/ s[s1]=‘\0’; } main() { char str[100],s[100]; printf(\nPlease enter string:); scanf(%s,str); fun(str,s); printf(The result is: %s\n,s); } 【答案及难度指数】★★★ (1)for(i=0;is1;i++) (2)s[2*s1]=‘\0’; 3.请编写函数fun,其功能是:将两个两位数的正整数x、y合并成一个整数放在z中。合并的方式是:将x的十位和个位依次放在z的个位和百位上,y的十位和个位数依次在z的千位和十位上。 例如,当x=12,y=34,调用该函数后,z=3241。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int x,int y,long *z) { } main() { int x,y; long z; FILE *out; printf( x,y: ); scanf(%d%d,x,y); fun(x,y,z); printf( The result is :%ld\n,z); out= (outfile.dat,w); for(x=0;x10;x++) { fun(x+77,x+66,z); fprintf(out,%ld\n,z); } fclose (out); } 【答案及难度指数】★★ *z=(y/10)*1000+(x%10)*100+(y%10)*10+x/10; 77 1.请补充fun函数,该函数的功能是计算并输出下列多项式的值: 例如,若主函数从键盘给n输入50后,则输出为S=1.960784。 请勿改动主函数main与其他函数中的任何); scanf(%d,n); s=fun(n); printf(The result is: %f\n\n,s); } 【答案及难度指数】★★★ (1)double (2)j 2.下列给定程序中函数fun的功能是:输出N行N列正方阵,然后求两条对角线上各元素之和,返回此和数。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # define N 5 /*******error********/ int fun(int n,int a[][]) { int i,j,sum=0; printf(\nThe %d x %d matrix:\n,N,N); for(i=0;in;i++) { /******error*********/ for(j=0;jn;j++) printf(%4f,a[i][j]); printf(\n); } for(i=0;in;i++) sum+=a[i][i]+a[i][n-i-1]; if(n%2!=0) sum-=a[n/2][n/2]; return(sum); } main() { int x[N][N]={{1,2,3,4,5},{2,3,4,5,1}, {3,4,5,1,2},{4,5,1,2,3},{5,4,3,2,1}}; printf(\nThe sum of all elements on 2 diagnal is %d.,fun(N,x)); } 【答案及难度指数】★★★ (1)int fun(int n,int a[][N]) (2)printf(%4d,a[i][j]); 3.请编写一个函数fun,它的功能是:计算n门课程的平均分,计算结果作为函数值返回。 例如,若有5门课程的成绩是88、92、80、61.5、55;则函数的值为75.30。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h float fun(float *b,int m) { } main() { float s[10]={88,92,80,61.5,55},aver; FILE *out; aver=fun(s,5); printf(\nAverage s is :%5.2f\n,aver); out= (outfile.dat,w); fprintf(out,%5.2f,aver); fclose (out); } 【答案及难度指数】★★ float ave=0.0; int i; for(i=0;im;i++) ave+=b[i]; ave/=m; return ave; 76 1.请补充fun函数,该函数的功能是:寻找两个整数之间的所有素数(包括这两个整数),把结果保存在数组a中,函数返回素数的个数。 例如,输入3和18,则输出为3 5 7 11 13 17。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # define N 500 int fun(int n,int m,int a[N]) { int i,j,k=0,flag; for(j=n;j=m;j++) { ___1___; for(i=2;ij;i++) if(___2___) { flag=0; break; } if(___3___) a[k++]=j; } return k; } main() { int n=0,m=0,i,k; int a[N]; printf( n\n); scanf(%d,n); printf( m\n); scanf(%d,m); for(i=0;im-n;i++) a[i]=0; k=fun(n,m,a); for(i=0;ik;i++) printf(%4d,a[i]); } 【答案及难度指数】★★★ (1)flag=1 (2)j%i==0 (3)flag==1 2.下列给定程序中函数fun的功能是:传入一个整数n,计算如下公式的值: 例如,若输入5,则应输出-0.283333。 请修改函数fun中的错误或在横线处填上适当的s-=1.0/i; /s-=(double)1/i (2)return s; 3.请编写函数fun,其功能是:将两个两位数的正整数a、b合并成一个整数放在c中。合并的方式是:将a的十位和个位依次放在c的百位和个位上,b的十位和个位依次放在c的千位和十位上。 例如,当a=45,b=12,调用该函数后,c=1425。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int a,int b,long *c) { } main () { int a,b; long c; FILE *out; printf( a,b:); scanf (%d%d,a,b); fun(a,b,c); printf(The result is: %ld\n,c); out= (outfile.dat,w); for(a=0;a10;a++) { fun(a+28,a+82,c); fprintf(out,%ld\n,c); } fclose (out); } 【答案及难度指数】★★ *c=(b/10)*1000+(a/10)*100+(b%10)*10+a%10; 75 1.请补充函数fun,该函数的功能是比较字符串s1和s2的大小,并返回比较的结果。 例如,当sr1=abcd,s2=abc时,fun函数返回s1s2。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # define N 80 char *fun(char *s1,char *s2) { char *t1=s1,*t2=s2; while(*t1 *t2) { if(___1___) return ; if(___2___) return ; t1++; t2++; } if(*t1==*t2) return ==; if(*t1==___3___) return ; else return ; } main() { char s1[N],s2[N]; printf(Please s1:\n); gets(s1); printf(Please s2:\n); gets(s2); printf(The result is\n); printf(s1 %s s2,fun(s1,s2)); } 【答案及难度指数】★★★ *t1*t2 (2)*t1*t2 (3)’\0’ 2.下列给定程序中,函数fun的功能是应用递归算法求某数b的平方根。求平方根的迭代公式如下: 例如,2的平方根值为1.414214。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include math.h /*******error*********/ fun(double b,double x0) { double x1,y; x1=(x0+b/x0)/2.0; /*******error*********/ if(abs(x1-x0)=1e-6) y=fun(b,x1); else y=x1; return y; } main() { double n; printf(Enter n: ); scanf(%lf,n); printf(The square root of %lf is %lf\n,n,fun(n,1.0)); } 【答案及难度指数】★★★ double fun(double b,double x0) (2)if(fabs(x1-x0)=1e-6) 3.程序定义了M×M的二维数组,并在主函数中自动赋值。请编写函数fun(int [][M],int n),该函数的功能是使数组左下半三角元素中的值乘以n。例如,若n的值为0,matrix数组中的值为: ,则返回主程序后,matrix数组中的值应为: 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # include stdlib.h # define M 3 void fun(int matrix[][M],int n) { } main() { int matrix[M][M],n,i,j; FILE *out; printf(The array \n); for(i=0;iM;i++) { for(j=0;jM;j++) { matrix[i][j]=rand()%10; printf(%4d,matrix[i][j]); } printf(\n); } n=rand()%4; printf(n=%4d\n,n); fun(matrix,n); printf(THE RESULT\n); for(i=0;iM;i++) { for(j=0;jM;j++) printf(%4d,matrix[i][j]); printf(\n); } out= (outfile.dat,w); for(i=0;iM;i++) for(j=0;jM;j++) matrix[i][j]=i*j+1; fun(matrix,9); for(i=0;iM;i++) { for(j=0;jM;j++) fprintf(out,%4d,matrix[i][j]); fprintf(out,\n); } fclose (out); } 【答案及难度指数】★★ int i,j; for(i=0;iM;i++) for(j=0;j=i;j++) matrix[i][j]=matrix[i][j]*n; 74 1.请补充fun函数,该函数的功能是在字符串的最前端加入num个*号,形成新串且覆盖原串。注意:字符串的长度最长允许为49。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # include conio.h void fun(char str[],int num) { char s[50],*p; int i; p=___1___; for(i=0;inum;i++) s[i]=‘*’; do { s[i]=___2___; i++; } while(___3___); s[i]=0; strcpy(str,s); } main() { int num; char str[50]; printf(\nEnter a string:); gets(str); printf(\nThe string\%s\\n,str); printf(\nEnter number of*:); scanf(%d,num); fun(str,num); printf(\nThe result String:\%s\ \n,str); } 【答案及难度指数】★★★ str (2)*p++ (3)*(p) 2.下列给定程序中,fun函数的功能是:求出以下分数序列的前n项之和: 和值通过函数值返回main()函数。例如,若n=5,则应输出8.391667。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ fun(int n) { int x=2,y=1,z,i; double result=0.0; for(i=1;i=n;i++) { result=result+1.0*x/y; /*******error********/ z=x; x+=y; y+=z; } return result; } main() { int n=5; printf(\nThe value of fun is :%lf\n, fun(n)); } 【答案及难度指数】★★★ (1)double fun(int n) (2)y=z; 3. 请编写函数fun,其功能是将两个两位数的正整数x、y合并成一个整数放在z中。合并的方式是:将x的十位和个位数依次放在z的个位和百位上,y的十位和个位依次放在z的十位 和千位上。 例如,当x=12,y=34,调用该函数后,z=4231。 请勿改动主函数main与其他函数中的任何请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h void fun(char *a,char *b,char *s) { int i=___1___; while(*a ___2___ *b) { if(*a*b) s[i]=*b; else s[i]=*a; if(*a) a++; if(*b) b++; i++; } } main() { char s1[10]=aBCDeFgH,s2[10]=ABcd, s[80]={‘\0’}; fun(s1,s2,s); printf(The string s1:); puts(s1); printf(The string s2:); puts(s2); printf(The result s:); puts(s); } 【答案及难度指数】★★★ (1)0 (2)|| 2.下列给定程序中,函数fun的功能是:根据整型参数n,计算如下公式的值: 例如,若n=4,则应输出0.600000。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ fun(int n) { double x=1; int i; /*******error*********/ for(i=2;in;i++) x=1.0/(1+x); return x; } main() { int n; printf(\nPlease enter n: ); scanf(%d,n); printf(x%d=%lf\n,n,fun(n)); } 【答案及难度指数】★★ (1)double fun(int n) (2)for(i=2;i=n;i++) 3.请编写函数fun,其功能是:计算并输出给定10个数的方差: 例如,给定的10个数为76.0、65.0、72.0、85.0、57.0、67.0、45.0、92.0、44.0、58.0,则输出为F=14.982990。 请勿改动主函数main与其他函数中的任何//初始化变量 for(i=0;i10;i++) //求公式中y的值 f1+=y[i]; f1/=10; for(j=0;j10;j++) //求公式中给出的根号下的部分 f+=(y[j]-f1)*(y[j]-f1); f/=10; f=pow(f,0.5);//求平方根 return f; 72 1.请补充fun函数,该函数的功能是:按0到9统计一个字符串中的奇数数字字符各自出现的次数,结果保存在数组num中。注意:不能使用字符串库函数。 例如,输入:g1ters4543123564879fgfd,结果为:1=2,3=2,5=2,7=1,9=1。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # define N 500 void fun(char *t,int count[]) { int i,j; int a[10]; char *p=t; for(i=0;i10;i++) { count[i]=0; a[i]=0; } while(___1___) { if(*p=‘0’ *p=‘9’) ___2___; p++; } for(i=1,j=0;i10;i=i+2,j++) ___3___; } main() { char s[N]; int count[10],i; printf(\nPlease enter a char string:); gets(s); printf(\nThe original string\n); puts(s); fun(s,count); printf(\nThe countber of leter\n); for(i=0;i5;i++) { printf(\n); printf(%d=%d ,2*i+1,count[i]); } printf(\n); } 【答案及难度指数】★★★ (1)*p (2)a[*p-’0’]++ (3)count[j]=a[i] 2.下列给定程序中,函数fun的功能是:从字符串s中删除所有小写字母c。 请修改程序中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h void fun(char *str) { int i,j; for(i=j=0;str[i]!=‘\0’;i++) /****error******/ if(str[i]!=‘c’) str[j]=str[i]; /****error******/ str[i]=‘\0’; } main() { char str[100]; printf(Enter a string with ‘c’: ); gets(str); printf(The original string :); puts(str); fun(str); printf(The string after deleted:); puts(str); printf(\n\n); } 【答案及难度指数】★★ str[j++]=str[i]; (2)str[j]=‘\0’; 3.M名学生的成绩已在主函数中放入一个带头节点的链表结构中,a指向链表的头节点。请编写函数fun,它的功能是:求出平均分,由函数值返回。 例如,若学生的成绩是69、85、91、72、64,则平均分应当是76.200。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include stdlib.h # define M 5 struct list { double s; struct list *next; }; typedef struct list SCORE; double fun(SCORE *a) { } SCORE *creat (double *stu) { SCORE *a,*p,*q; int i=0; a=p=(SCORE*) malloc (sizeof (SCORE)); p-s=0; while(iM) { q=(SCORE*) malloc (sizeof (SCORE)); q-s=stu[i]; i++; p-next=q; p=q; } p-next=0; return a; } outlist (SCORE *a) { SCORE *p; p=a-next; printf( a ); do { printf(-%4.1f,p-s); p=p-next; } while(p!=0); printf(\n\n); } main () { double stu[M]={69,85,91,72,64},ave; SCORE *a; FILE *out; a=creat(stu); outlist(a); ave=fun(a); printf(ave=%6.3f\n,ave); out=(outfile.dat,w); fprintf(out,%6.3f,ave); fclose (out); } 【答案及难度指数】★★★ double aver=0.0;//初始化平均值 while(a!=NULL) //如果头指针不指向链表尾,就累加链表中成绩 { aver+=a-s; //累加成绩 a=a-next; //指向下一个节点 } aver/=M; //求平均分 return aver; 71 1.请补充main函数,该函数的功能是:从键盘输入一个字符串并保存在字符s1中,把字符串s1中下标为奇数的字符保存在字符串s2中并输出。例如,当s1=asdfgh时,则s2=sfh。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # define N 80 main() { char s1[N],s2[N]; char *temp1=s1,*temp2=s2; int i=0,j=0; printf(Please Enter the string:\n); scanf(___1___); printf(The origial string is:\n); while(*(temp1+j)) { printf(___2___,*(temp1+j)); j++; } for(i=1;ij;i+=2) *temp2++=*(s1+i); *temp2=‘\0’; printf(The new string is:%s\n,___3___); } 【答案及难度指数】★★★ (1)%s,s1 (2)%c (3)s2 【 2.在主函数中从键盘输入若干个数放入数组中,用0结束输入并放在最后一个元素中。下列给定程序中,函数fun的功能是:计算数组元素中值为正数的平均值(不包括0)。例如,数组中元素的值依次为-2 43 56 -9 0,则程序的运行结果为49.500000。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h double fun(int a[]) { /******error*********/ int sum=0.0; int t=0,i=0; while(a[i]!=0) { if(a[i]0) { sum+=a[i]; t++; } i++; } /*******error********/ sum\=t; return sum; } main() { int a[500]; int i=0; printf(\nPlease enter some data (end with 0):); do { scanf(%d,a[i]); } while(a[i++]!=0); printf(%lf\n,fun(a)); } 【答案及难度指数】★★ double sum=0.0; (2)sum/=t; 3.假定输入的字符串中只包含字母和#号,请编写函数fun,它的功能是:将字符串尾部 的#号全部删除,前面和中间的#号不删除。 例如,若字符串中的内容为###a#b###c##d####,删除后,字符串中的内容则应当是###a#b###c##d。在编写函数时,不得使用C语言提供的字符串函数。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # include string.h void fun(char *s) { } main() { char str[100]; FILE *out; printf(Enter a string:\n); gets(str); fun(str); printf(The string after deleted:\n); puts(str); out= (outfile.dat,w); strcpy(str,###A#BC#DE#F#G######); fun(str); fprintf(out,%s,str); fclose (out); } 【答案及难度指数】★★★ int i=0; char *p,*q; p=q=s; while(*p) p++; p--; while(*p==‘#’) p--; while(q=p) { s[i]=*q; i++; q++; } s[i]=‘\0’; 70 1.请补充fun函数,该函数的功能是判断一个数的个位数字和百位数字之和是否等于其十位上的数字,是则返回yes!,否则返回no!。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h char *fun(int n) { int t,s,a; t=n%10; s=n/10%10; a=___1___; if((t+a)==s) return ___2___; else return ___3___; } main() { int len=0; printf(Please a data \n ); scanf(%d,len); printf( The result is : ); printf(%s,fun(len)); } 【答案及难度指数】★★★ (1)n/100%10 (2)yes! (3)no! 2.下列给定程序中函数fun的功能是求出以下分数列的前m项之和, 和值通过函数值返回main函数。例如,若m=10,则应输出16.479905。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error********/ fun(int m) { int x,y,z,i; double s; s=0.0; x=2; y=1; for(i=1;i=m;i++) { /********error********/ s=s+(Double)x/y; z=x; x=x+y; y=z; } return s; } main() { int m=10; printf(\nThe value of fun is :%lf\n, fun(m)); } 【答案及难度指数】★★ (1)double fun(int m) (2)s=s+(double)x/y; 3.请编写函数fun,其功能是:将所有大于1且小于整数n的非素数存入a所指数组中,非素数的个数通过m传回。 例如,若输入11,则应输出4 6 8 9 10。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int n,int *m,int a[]) { } main() { int k,h,c[100]; FILE *out; printf(\nPlease enter an integer number between 10 and 100: ); scanf(%d,h); fun(h,k,c); printf(\n\nThere are %d non-prime numbers less than %d: ,k,h); for(h=0;hk;h++) printf(\n %4d,c[h]); out=(outfile.dat,w); fun(10,k,c); fprintf(out,%d\n,k); for(h=0;hk;h++) fprintf(out,%d\n,c[h]); fclose(out); } 【答案及难度指数】★★★ int i,j; int t=0; //初始化数组个数 for(i=2;in;i++) //循环判断小于n的数是否为素数 { j=2; while(ji) { if(i%j==0) //如果i不是素数 { a[t]=i; t++; break; } j++; } *m=t; } 69 1.函数fun的功能是:将形参b所指数组中的前半部分元素的值和后半部分元素的值对换。形参n中存放数组中数据的个数,若n为奇数,则中间的元素不动。例如,若a所指数组中的数据依次为:11 22 33 1 44 55 66,则调换后为:44 55 66 1 11 22 33。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define M 7 void fun(int b[],int n) { int j,temp,p; p=(n%2==0) ? n/2 : n/2+___1___; for(j=0;jn/2;j++) { temp=b[j]; b[j]=b[p+___2___]; ___3___=temp; } } main() { int x[M]={11,22,33,1,44,55,66},i; printf(\nThe original data :\n); for(i=0;iM;i++) printf(%4d ,x[i]); printf(\n); fun(x,M); printf(\nThe data after moving :\n); for(i=0;iM;i++) printf(%4d ,x[i]); printf(\n); } 【答案及难度指数】★★★ (1)1 (2)j (3)b[p+j] 2.下列给定程序中函数fun的功能是:将字符串中的内容按逆序输出,但不改变字符串中的内容。例如,若字符串为asdf,则应输出fdsa。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h /****error******/ void fun(char s) { if(*s) { fun(s+1); printf(%c,*s); } } main() { char str[10]=asdf; printf(do string=%s\n after=,str); fun(str); printf(\n); } 【答案及难度指数】★★ void fun(char *s) 3.已知学生的记录由学号和学习成绩构成,M名学生的数据已存入stu结构体数组中。请编写函数fun,该函数的功能是:找出成绩最高的学生记录,通过形参返回主函数(规定只有一个最高分)。已给出函数的首部,请完成该函数。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # include conio.h # define M 10 typedef struct ss { char num[10]; int s; } SCORE; void fun(SCORE stu[],SCORE *s) { } main() { SCORE stu[M]={{02,69},{04,85}, {01,91},{08,64},{06,87},{015,85},{013,91},{012,64},{011,91},{017,64}},m; int i; FILE *out; printf(The original data \n); for(i=0;iM;i++) printf(N0=%s Mark=%d\n,stu[i]. num,stu[i].s); fun(stu,m); printf(THE RESULT \n); printf( The hight : %s,%d\n, m.num,m.s); out= (outfile.dat,w); fprintf(out,%s\n%d,m.num,m.s); fclose (out); } 【答案及难度指数】★★★ int i,max; max=stu[0].s; for(i=0;iM;i++) if(stu[i].smax) { max=stu[i].s; *s=stu[i]; } 68 1.请补充fun函数,该函数的功能是:把从主函数中输入的字符串s2接在字符串s1后面。 例如,输入:s1=Hi,,s2=Welcome!,结果输出:Hi,Welcome!。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # define LEN 100 void fun(char *s1,char *s2) { int i=0; char *p1=s1; char *p2=s2; while(___1___) i++; for(;___2___;i++) *(p1+i)=___3___; *(p1+i)=‘\0’; } main() { char s1[LEN],s2[LEN]; printf(Please the string s1 and s2\n ); printf( \ns1:); gets(s1); printf( \ns2:); gets(s2); printf(The string s1 and s2\n); puts(s1); puts(s2); fun(s1,s2); printf(The new string is\n); puts(s1); } 【答案及难度指数】★★★ (1)*(p1+i) (2)*p2 (3)*p2++ 2.下列给定程序中函数fun的功能是:将长整型数中每一位上为偶数的数依次取出,构成一个新数放在b中。高位仍在高位,低位仍在低位。例如,当a中的数为123456时,则b中的数为246。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h void fun(long a,long *b) { /*******error********/ int d; long s1=0; *b=0; while(a0) { d=a%10; if(d%2==0) { *b=d*s1+*b; s1*=10; } /*******error********/ a\=10; } } main() { long a,b; printf(\nPlease enter data:); scanf(%ld,a); fun(a,b); printf(The result is :%ld\n,b); } 【答案及难度指数】★★ long s1=1; (2)a/=10; 3. 请编写函数fun,其功能是:将str所指字符串中ASCII值为偶数的字符删除,串中剩余字符形成一个新串放入s所指的数组中。 例如,若str所指字符串中的请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h void fun(char *str,char s[]) { } main() { char str[100],s[100],m[]=\nPlease enter string:; FILE *out; printf(m); scanf(%s,str); fun(str,s); printf(\nThe result is :%s\n,s); out= (outfile.dat,w); fun(m,s); fprintf(out,%s,s); fclose (out); } 【答案及难度指数】★★★ int i,j=0,n=strlen(str); for(i=0;in;i++) if(str[i]%2!=0) { s[j]=str[i]; j++; } s[j]=‘\0’; 67 1.程序的功能是计算,例如,输入参数3,结果为10。 请勿改动主函数main与其他函数中的任何内容,仅在横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h long fun(int n) { int i; long f; f=___1___; for(i=1;i=n;i++) f=___2___; return f; } main() { long s; int k,n; printf(Please the data:); scanf(%d,n); s=___3___; for(k=0;k=n;k++) s=___4___; printf(the resutl is : %ld\n,s); } 【答案及难度指数】★★★ (1)1 (2)f*i (3)0 (4)s+fun(k) 2.下列给定程序中函数fun的功能是:统计子字符串substr在字符串str中出现的次数。例如,若字符串为aaaskkaaas,子字符串为as,则应输出2。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h /*******error********/ int fun(char *s,*str) { int i,j,k,num=0; /*******error*********/ for(i=0,s[i],i++) for(j=i,k=0;str[k]==s[j];k++,j++) if(str[k+1]==‘\0’) { num++; break; } return num; } main() { char s[100],str[80]; printf( a string:); gets(s); printf( a substring:); gets(str); printf(%d\n,fun(s,str)); } 【答案及难度指数】★★ (1)int fun(char *s,char *str) (2)for(i=0;s[i];i++) 3.请编写函数fun,其功能是:计算并输出当x0.97时下列多项式的值,直到|Fn-Fn-1|0.000001为止。 例如,若主函数从键盘给x输入0.33后,则输出为f=1.153256。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include math.h double fun(double x) { } main() { int i; double x,f; FILE *out; printf( x: ); scanf(%lf,x); f=fun(x); printf(f=%f\n,f); out= (outfile.dat,w); for(i=20;i30;i++) fprintf(out,%f\n,fun(i/100.0)); fclose (out); } 【答案及难度指数】★★★ double f1=1.0,p=1.0,sum=0.0,f0,t=1.0; int n=1; do { f0=f1; //前一项 sum+=f0; //求和 t*=n; //每一项中的阶乘项 p*=(0.5-n+1)*x;//每一项中的分子 f1=p/t; //每一项 n++; } while(fabs(f1-f0)=1e-6);//循环条件 return sum; 66 1.请补充函数fun,该函数的功能是:统计所有小于等于x(x2)的素数的个数,素数的个数作为函数值返回。例如,输入x=20,结果:2,3,5,7,11,13,17,19。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h int fun(int x) { int i,j,count=0; printf(\nThe prime number between 2 to %d\n,x); for(i=2;i=x;i++) { for(___1___;ji;j++) if(___2___%j==0) break; if(___3___=i) { count++; printf(count%15 ? %5d : \n%5d,i); } } return count; } main() { int x=20,result; result=fun(x); printf(\nThe number of prime is : %d\n,result); } 【答案及难度指数】★★★ j=2 (2)i (3)j 2.下列给定程序中函数fun的功能是:计算m!。例如,给m输入3,则输出6.000000。 请修改程序中的错误,使程序能输出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include conio.h double fun(int m) { double result=1.0; /********error********/ if m==0 return 1.0; while(m1 m170) /*******error*********/ result=m--; return result; } main() { int m; printf( m:); scanf(%d,m); printf(\n\n%d!=%1f\n\n,m,fun(m)); } 【答案及难度指数】★★ if(m==0) (2)result*=m--; 3.生的记录由学生和成绩组成,M名学生的数据已在主函数中放入结构体数组stu中,请编写函数fun,它的功能是:把分数最高的学生数据放在high所指的数组中,注意:分数最高的学生可能不止一个,函数返回分数最高的学生的人数。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若 干语句。 注意:部分源程序给出如下。 # include stdio.h # define M 10 typedef struct { char num[10]; int s; } SCORE; int fun(SCORE *p,SCORE *q) { } main () { SCORE stu[M]={{02,69},{04,85}, {01,91},{08,64},{06,87},{015,85},{013,91},{012,64},{011,91},{017,64}}; SCORE high[M]; int i,n; FILE *out; n=fun(stu,high); printf(The %d high score :\n,n); for(i=0;in;i++) printf(%s %4d\n,high[i].num, high[i].s); printf(\n); out= (outfile.dat,w); fprintf(out,%d\n,n); for(i=0;in;i++) fprintf(out,%4d\n,high[i].s); fclose (out); } 【答案及难度指数】★★★ int i,j=0,n=0,max; max=p[0].s; for(i=0;iM;i++) if(p[i].smax) max=p[i].s; for(i=0;iM;i++) if(p[i].s==max) { *(q+j)=p[i]; j++; n++; } return n; 65 1.请补充fun函数,该函数的功能是求能整除k且是偶数的数,把这些数保存在数组a,并按从大到小输出。 例如,当k=40时,依次输出40 20 10 8 4 2。 请勿改动主函数main与其他函数中的任何int i; int j=0; for(___1___;i=k;i++) if(k%i==0 ___2___ i%2==0) a[j++]=i; printf(\n\n ); for(i=___3___;i=0;i--) printf(%d ,a[i]); } main() { int k=1; int a[100]; printf(\nPlease k\n); scanf(%d,k); fun(k,a); } 【答案及难度指数】★★★ i=1 (2) (3)--j 2.下列给定程序的功能是:读入一个英文文本行,将其中每个单词的第一个字母改成大写,然后输出此文本行(这里的单词是指由空格隔开的字符串)。例如,若输入good luck!,则应输出Good Luck!。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include ctype.h # include string.h # include stdio.h /*******error*********/ void top(char s) { int i=0; for(;*s;s++) if(i) { if(*s==‘ ‘) i=0; } else { if(*s!=‘ ‘) { i=1; *s=toupper(*s); } } } main() { char str[81]; printf(\nPlease enter an English text line: ); gets(str); printf(\n\nBefore changing:\n %s,str); top(str); printf(\nAfter changing:\n %s\n,str); } 【答案及难度指数】★★ void top(char *s) 3.假定输入的字符串中只包含字母和#号。请编写函数fun,它的功能是:除了字符串前导和尾部的#号之外,将串中其他#号全部删除。形参r已指向字符串中第一个字母,形参v已指向字符串中最后一个字母。在编写函数时,不得使用C语言提供的字符串函数。 例如,若字符串中的内容为####a#bc#def##g#####,删除后,字符串中的内容则应当是####abcdefg#####。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # include string.h void fun(char *s,char *r,char *v) { } main() { char str[100],*p,*q; FILE *out; printf(Enter a string:\n); gets(str); p=q=str; while(*p) p++; p--; while(*p==‘#’) p--; while(*q==‘#’) q++; fun(str,q,p); printf(The string after deleted:\n); puts(str); out= (outfile.dat,w); strcpy(str,#####a#b#c#d######); fun(str,str+4,str+13); fprintf(out,%s,str); fclose (out); } 【答案及难度指数】★★★ int i=0; char *q=s; while(qr) { s[i]=*q; q++; i++; } while(qv) { if(*q!=‘#’) { s[i]=*q; i++; } q++; } while(*q) { s[i]=*q; i++; q++; } s[i]=‘\0’; 64 1.函数fun的功能是:逆置数组元素中的值,形参m给出数组中数据的个数。 例如,若x所指数组中的数据依次为:9、8、7、6、5,则逆置后依次为:5、6、7、8、9。 请勿改动主函数main与其他函数中的任何请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h int fun(int x,int y,int z) { if(x+yz y+zx x+zy) { /*******error*********/ if(x==y y==z) return 1; else if(x==y || y==z || x==z) return 2; else /*******error*********/ return 3; } else return 0; } main() { int x,y,z,shape; printf(\n x,y,z: ); scanf(%d%d%d,x,y,z); printf(\nx=%d,y=%d,z=%d\n,x,y,z); shape=fun(x,y,z); printf(\n\nThe shape : %d\n,shape); } 【答案及难度指数】★★ return 3; (2)return 1; 3.假定输入的字符串中只包含字母和#号,请编写函数fun,它的功能是:删除字符串中所有的#号。在编写函数时,不得使用C语言提供的字符串函数。 例如,若字符串中的内容为##w#el##come###,删除后,字符串中的内容则应当是welcome。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h void fun(char *s) { } main() { char str[81]; FILE *out ; printf(Enter a string:\n); gets(str); fun(str); printf(The string after deleted:\n); puts(str); out=(outfile.dat,w); strcpy(str,###T#ES#T#######); fun(str); fprintf(out,%s,str); fclose(out); } 【答案及难度指数】★★★ int i=0;char *p=s; //工作指针p指向字符串s while(*p) //当p不指向字符串尾符 { if(*p!=‘#’) //指针p指向的字符不是# { s[i]=*p; //将p指向的字符复制到字符串s i++; //s下标加1 } p++; //指针指向下一个字符 } s[i]=‘\0’;//新串加尾符 63 1.给定程序中,函数fun的功能是:在形参s所指字符串中的每个非数字字符之后插入一个*号。 例如,形参s所指的字符串为:a1bc45sdtg56f,则执行结果为:a*1b*c*45s*d*t*g*56f*。 请勿改动主函数main与其他函数中的任何%s\n,str); } 【答案及难度指数】★★★ (2)0 (3)str[j] 2.下列给定程序中,函数fun的功能是:将大写字母转换为对应小写字母之后的第五个字母,若为小写字母为v~z,使小写字母的值减21,转换后的小写字母作为函数值返回。例如,若形参是字母A,则转换为小写字母f;若形参是字母W,则转换为小写字母b。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include ctype.h char fun(char ch) { /******error**********/ if(ch=‘A’ ch=‘Z’) ch=ch-32; /*******error*********/ if(ch=‘a’ ch=‘u’) ch=ch-5; else if(ch=‘v’ ch=‘z’) ch=ch-21; return ch; } main() { char ch1,ch2; printf(\nEnter a letter(A-Z): ); ch1=getchar(); if(isupper(ch1)) { ch2=fun(ch1); printf(\n\nThe letter %c change to %c\n,ch1,ch2); } else { printf(\nEnter (A-Z)!\n); } } 【答案及难度指数】★★ ch=ch+32; (2)ch=ch+5; 3.编写一个函数fun,它的功能是:实现两个字符串的连接(不使用库函数strcat),即把str2所指的字符串连接到str1所指的字符串后。 例如,分别输入下面两个字符串: just-- test 则程序输出: just--test 请勿改动主函数main与其他函数中的任何//初始化串1个数n,下标i char *p=str1,*q=str2; //定义指针p,q指向串1、串2 while(*p) //循环求第一个串中字符个数 { p++; //指向下一个字符 n++; //字符个数加1 } i=n; //i赋值为串1的最后位置 while(*q) //循环中将串2放在串1后面 { str1[i]=*q; //将q指向的字符依次放在串str1后面 q++; //指向下一个字符 i++; //下标加1 } str1[i]=‘\0’; //在新串后加尾符 62 1.给定程序中,函数fun的功能是:将s所指字符串中的所有非数字字符移到所有数字字符之后,并保持数字字符串和非数字字符串原有的先后次序。 例如,形参s所指的字符串为:asf34fgrt5657gngjh78。则执行结果为:34565778asffgrtgngjh。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h void fun(char *str) { int i,j=0,k=0; char temp1[80],temp2[80]; for(i=0;str[i]!=‘\0’;i++) if(str[i]=‘a’ str[i]=‘z’) { ___1___; j++; } else { temp1[k++]=str[i]; } temp2[j]=0; temp1[k]=0; for(i=0;ik;i++) ___2___; for(i=0;i___3___;i++) str[k+i]=temp2[i]; } main() { char str[100]=asf34fgrt5657gngjh78; printf(\nThe original string is : %s\n,str); fun(str); printf(\nThe result is : %s\n,str); } 【答案及难度指数】★★★ (1)temp2[j]=str[i] (2)str[i]=temp1[i] (3)j 2.下列给定程序中,函数fun的功能是:计算并输出max以内最大的10个素数之和。high由主函数传给fun函数。若max的值为50,则函数的值为300。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include math.h int fun(int max) { int sum=0,n=0,j,flag; while((max=2) (n10)) { flag=1; for(j=2;j=max/2;j++) /********error********/ if(max%j==0) { flag=0; break } if(flag) { sum+=max; n++; } max--; } return sum; } main() { printf(%d\n,fun(50)); } 【答案及难度指数】★★ break; 3.请编写函数fun,该函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。 例如,若字符串数组中的M个字符串为: 1111 2222222 33 4444 则合并后的字符串的内容应是11112222222334444。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # define M 4 # define N 20 void fun(char str[M][N],char *a) { } main() { char matrix[M][N]={1111,2222222, 33,4444},i; char str [100]={****************}; FILE *out ; printf(The string:\n); for(i=0;iM;i++) puts(matrix[i]); printf(\n); fun(matrix,str); printf(The string:\n); printf(%s,str); printf(\n\n); out= (outfile.dat,w); fprintf(out,%s,str); fclose (out); } 【答案及难度指数】★★★ int i,j,k=0; for(i=0;iM;i++) { for(j=0;jN;j++) if(*(*(str+i)+j)) //如果不指向行的尾 { a[k]=*(*(str+i)+j); //将行中的值赋值给数组a k++; //数组下标加1 } else //如果指向尾,则跳出这一行 break; a[k]=‘\0’; //数组加尾符 } 61 1.s为一个字符序列,请补充fun函数,该函数的功能是:查找s中值为a的元素,返回找到值为a的元素个数,并把这些值为a的元素下标依次保存在数组str中。 例如,在testtest中查找e,结果为2,下标依次为1、5。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # define M 100 int str[M]; int fun(char *s,char ch) { int i=0,n=0; char t=ch; char *p=s; while(*p) { if(___1___) ___2___; p++; i++; } return ___3___; } main() { char s[M]; char ch; int i,n; printf(Please the original string\n ); gets(s); printf(The Original string is :\n); puts(s); printf( character\n); scanf(%c,ch); n=fun(s,ch); printf( \nThe number of character is: %d\n,n); printf(The position of character:\n); for(i=0;in;i++) printf( %d ,str[i]); } 【答案及难度指数】★★★ *p==t (2)str[n++]=i (3)n 2.下列给定程序中,函数fun的功能是:用递归算法计算斐波拉契级数数列中第n项的值。 从第1项起,斐波拉契级数序列为1、1、2、3、5、8、…例如,若给n输入7,则该项的斐波拉契级数值为13。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h long fun(int m) { /*******error*********/ switch(m); { case 0: return 0; /********error********/ case 1; case 2: return 1; } return (fun(m-1)+fun(m-2)); } main() { long a; int n; printf( n: ); scanf(%d,n); printf(n=%d\n,n); a=fun(n); printf(a=%d\n\n,a); } 【答案及难度指数】★★ switch(m) (2)case 1: 3.请编写函数fun,该函数的功能是:删除一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。 例如,若一维数组中的数据是: 1,1,1,2,2,3,3,3,3,4 删除后,数组中的内容应该是: 1,2,3,4 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # define M 100 int fun(int b[],int m) { } main() { int b[M]={1,1,1,2,2,3,3,3,3,4},i,m=10; FILE *out ; printf(The original data :\n); for(i=0;im;i++) printf(%3d,b[i]); m=fun(b,m); printf(\nThe data after deleted :\n); out= (outfile.dat,w); for(i=0;im;i++) { printf(%3d,b[i]); fprintf(out,%d\n,b[i]); } fclose (out); } 【答案及难度指数】★★★ int i,t,j=0,*p=b; t=p[0]; //设置临时变量t初值指向第一数组值 for(i=0;i=m;i++) if(t==p[i]) //当临时变量与数组中的某个值相同则跳出,比较下一个元素 ; else //如果临时变量与数组中值不同,则对临时变量重新赋值 { b[j]=t; t=p[i]; j++; } if(i=m) b[j]=t; return j; 60 1.给定程序的功能是将m个人员的考试成绩进行分段统计,考试成绩放在score数组中,各分段的人数存到a数组中:成绩为60~69的人数存到a[0]中,成绩为70~79的人数存到a[1]中,成绩为80~89的人数存到a[2]中,成绩为90~99的人数存到a[3]中,成绩为100的人数存到a[4]中,成绩为60分以下的人数存到a[5]中。 例如,当score数组中的数据是:90,54,90,77,68,88,59,94,75,98。调用该函数后,a数组中存放的数据应是:1 2 1 4 0 2。 请勿改动主函数main与其他函数中的任何内容,仅在横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h void fun(int score[],int a[],int m) { int i; for(i=0;i6;i++) a[i]=0; for(i=0;i___1___;i++) if(score[i]60) a[5]++; ___2___ a[(score[i]-60)/10]++; } main() { int i,score[100]={90,54,90,77,68, 88,59,94,75,98},a[6]; fun(___3___,a,10); printf(the result is: ); for(i=0;i6;i++) printf(%d ,a[i]); printf(\n); } 【答案及难度指数】★★★ m (2)else (3)score 2.下列给定程序中,函数fun的功能是:给定n个实数,输出平均值,并统计在平均值以上(含平均值)的实数个数。例如,n=8时,输入193.199、195.673、195.757、196.051、196.092、196.596、196.579、196.763,所得平均值为195.838750,在平均值以上的实数个数应为5。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ int fun(double a[],int n) int j,b=0; double sum=0.0; for(j=0;jn;j++) sum+=a[j]/n; printf(ave=%f\n,sum); for(j=0;jn;j++) if(a[j]=sum) b++; return b; } main() { double a[10]={195.673,195.757, 196.051,196.596,196.579}; printf(%d\n,fun(a,5)); } 【答案及难度指数】★★ int fun(double a[],int n){ 3.学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组STU,请编写函数fun,它的功能是:把指定分数范围SCORE; int fun(SCORE *p,SCORE *q,int ll,int hh) { } main () { SCORE stu[M]={{G002,69},{G004, 85},{G001,96},{G007,72},{G008,64},{G006,87},{G015,85},{G013,94},{G012,64},{G014,91}}; SCORE h[M],t; FILE *out; int i,j,n,low,heigh,k; printf(Enter 2 integer number low heigh : ); scanf (%d%d,low,heigh); if(heighlow) { k=heigh; heigh=low; low=k; } n=fun(stu,h,low,heigh); printf(The student ‘s data between %d----%d : \n,low,heigh); for(i=0;in;i++) printf(%s %4d\n,h[i].num,h[i].s); printf(\n); out= (outfile.dat,w); n=fun(stu,h,80,98); fprintf(out,%d\n,n); for(i=0;in-1;i++) for(j=i+1;jn;j++) if(h[i].sh[j].s) { t=h[i] ; h[i]=h[j]; h[j]=t; } for(i=0;in;i++) fprintf(out,%4d\n,h[i].s); fprintf(out,\n); fclose (out); } 【答案及难度指数】★★★ int i,j=0; //初始化题干范围//循环判断 if(p[i].s=llp[i].s=hh) //学生i的成绩p[i].s大于等于ll小于等于hh { q[j]=p[i]; //如果满足if表达式,则存入数组q j++; //数组下标加1,即满足条件的人数加1 } return j; //返回满足条件的人数j 59 1.请补充fun函数,该函数的功能是判断一个数是否为素数。该数是素数时,函数返回字符串yes!,否则函数返回字符串no!,并在主函数中输出。例如,输入13,返回yes!;输入8,返回no! 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h ___1___ { int i,j; j=1; for(i=___2___;im;i++) if(___3___) { j=0; break; } if(j==1 m1) return(yes!); else return(no!); } main() { int n=0; printf(Please a integer:); scanf(%d,n); printf(%s\n,fun(n)); } 【答案及难度指数】★★★ (1)char *fun(int m) (2)2 (3)m%i==0 2.下列给定程序中函数fun的功能是:先将在字符串str中的字符按逆序存放到s串中,然后把str中的字符按正序连接到s串的后面。例如,str中的字符串为ABCDE时,则s中的字符串应为EDCBAABCDE。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h # include string.h void fun(char *str,char *s) { int s1,i; s1=strlen(str); /*******error*********/ for(i=0;is1;i++) s[i]=str[s1-i]; for(i=0;is1;i++) s[s1+i]=str[i]; s[2*s1]=‘\0’; } main() { char str[100],s[100]; printf(\nPlease enter string str:); scanf(%s,str); fun(str,s); printf(The result is: %s\n,s); } 【答案及难度指数】★★ s[i]=str[s1-i-1]; / s[i]=str[s1-1-i]; 3.假定输入的字符串中只包含字母和#号。请编写函数fun,它的功能是:除了尾部的#号之外,将字符串中其他#号全部删除。形参p已指向字符串中的最后一个字母。在编写函数时,不得使用C语言提供的字符串函数。 例如,若字符串中的内容为###a#b#c#d#e###,删除后,字符串中的内容则应当是abcde###。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include conio.h # include string.h void fun(char *s,char *p) { } main() { char str[81],*t; FILE *out ; printf(Enter a string:\n); gets(str); t=str; while(*t) t++; t--; while(*t==‘#’) t--; fun(str,t); printf(The string after deleted:\n); puts(str); out= (outfile.dat,w); strcpy(str,###W#e#l#c#o#m#e####); fun(str,str+14); fprintf(out,%s,str); fclose (out); } 【答案及难度指数】★★★ int i=0; char *q=s; //q指向原串头 while(q=p) //由原串头开始到最后一个非#字符进行赋值 { if(*q!=‘#’) { s[i]=*q; i++; } q++; } while(*q) //将原串中的值赋值到新串 { s[i]=*q; i++; q++; } s[i]=‘\0’; 58 1.请补充main函数,该函数的功能是:求n!。 例如,5!=120。 仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何注意:部分源程序给出如下。 # include stdio.h # include conio.h main() { int i,n; long r=1; printf(Please n: ); scanf(%d,___1___); for(___2___;i=n;i++) ___3___; printf(The result %d!=%ld\n,n,r); } 【答案及难度指数】★ n (2)i=1 (3)r*=i 2.下列给定程序中,函数fun的功能是:统计一个无符号整数中各位数字值为0的个数,通过形参传回主函数,并把该整数中各位上最大的数字值作为函数值返回。例如,若输入无符号整数10080,则数字值为0的个数为3,各位上数字值最大的是8。 请修改函数fun中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h int fun(unsigned m,int *z) { int n=0,max=0,t; do { t=m%10; /*******error********/ if(t=0) n++; if(maxt) max=t; m=m/10; } while(m); /*******error********/ z=n; return max; } main() { unsigned m; int z,max; printf(\n m(unsigned): ); scanf(%d,m); max=fun(m,z); printf(\nThe result: max=%d z=%d\n, max,z); } 【答案及难度指数】★★★ if(t==0) (2)*z=n; 3.学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组student中,请编写函数fun,它的功能是:把高于平均分的学生数据放在c所指的数组中,高于平均分的学生人数通过形参n传回,平均分通过函数值返回。 请勿改动主函数main与其他函数中的任何SCORE; double fun(SCORE *a,SCORE *c,int *n) { } main() { SCORE student[M]={{01,91},{02, 69},{03,76},{04,85},{05,85}}; SCORE high[M],t;FILE *out ; int i,j,n; double ave; ave=fun(student,high,n); printf(The %d student data which is higher than %7.3f:\n,n,ave); for(i=0;in;i++) printf(%s %4.1f\n,high[i].num, high[i].s); printf(\n); out= (outfile.dat,w); fprintf(out,%d\n%7.3f\n,n,ave); for(i=0;in;i++) for(j=i+1;jn;j++) if(high[i].shigh[j].s) { t=high[i] ; high[i]=high[j]; high[j]=t; } for(i=0;in;i++) fprintf(out,%4.1f\n,high[i].s); fclose (out); } 【答案及难度指数】★★★ double aver=0.0; //初始化平均分为0 int i,j=0; *n=0; //人数指针n初始化 for(i=0;iM;i++) aver+=a[i].s; //求总分 aver/=M; //求平均分 for(i=0;iM;i++) if(a[i].saver) //如果学生的成绩大于平均分 { c[j]=a[i]; (*n)++; //大于平均分的人数加1 j++; //数组下标加1 } return aver; //返回平均分 57 1.请补充fun函数,fun函数的功能是求m的阶乘。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表 达式或语句。 注意:部分源程序给出如下。 # include stdio.h long fun(int m) { if(___1___) return (m*fun(___2___)); return ___3___; } main() { printf(8!=%ld\n,fun(8)); } 【答案及难度指数】★★ (1)m1 (2)m-1 (3)1 2.下列给定程序的功能是:读入一个整数n(2≤n≤5000),打印它的所有为素数的因子。例如,若输入整数1234,则应输出:2、617。 请修改程序中的错误,使程序能得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ Prime(int m); { int j,p; p=1; /*******error*********/ for(j=2;jm;j++) if!(m%j) { p=0; break; } return(p); } main() { int i,n; printf(\nplease enter an integer number between 2 and 5000:); scanf(%d,n); printf(\n\nThe prime factor(s) of %d is(are):,n); for(i=2;in;i++) if((!(n%i)) (Prime(i))) printf( %4d,,i); printf(\n); } 【答案及难度指数】★★ Prime(int m) (2)if(!(m%j)) 3.数组point中存放着m个人的成绩,请编写函数fun,它的功能是:返回高于平均分的人数,并将高于平均分的分数放在high所指的数组中。 例如,当point数组中的数据为50、60、65、70、75、80、88、90、95时,函数返回的人数应该是5,high中的数据应为75、80、88、90、95。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h int fun(int point[],int n,int high[]) { } main() { int j,m,high[9]; int point[9]={50,60,65,70,75,80, 88,90,95}; FILE *out; m=fun(point,9,high); printf(\nHigh the average point are :); out=(outfile.dat,w); for(j=0;jm;j++) { printf(%d ,high[j]); fprintf(out,%d\n0,high[j]); } fclose(out); } 【答案及难度指数】★★ int j,k=0,average=0; for(j=0;jn;j++) average+=point[j]; //统计总分数 average/=n;//求平均分 for(j=0;jn;j++) if(point[j]average) //逐个判断每个分数是否大于平均分 { high[k]=point[j]; //将高于平均分的人放入high数组 k++; //统计大于平均分的人数 } return k; 56 1.请补充fun函数,该函数的功能是:删除字符数组中比指定字符小的字符,指定字符从键盘输入,结果仍保存在原数组中。 例如,输入asdfghj,指定字符为f,则结果输出sfghj。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 100 void fun(char s[],char ch) { int i=0,j=0; while(s[i]) { if(s[i]ch) { ___1___; } else { ___2___; i++; } } ___3___; } main() { char str[N],ch; printf(Please a string:\n); gets(str); printf(The original string: \n); puts(str); printf(Please a character :\n); scanf(%c,ch); fun(str,ch); printf(The new string: \n); puts(str); } 【答案及难度指数】★★ (1)i++ (2)s[j++]=s[i] (3)s[j]=‘\0’ 2.下列给定程序中函数fun的功能是:判断一个整数m是否是素数,若是返回1,否则返回0。在main()函数中,若fun返回1,则输出YES,若fun返回0,则输出NO!。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h int fun(int n) { int i=2; while(i=n (n%i)) /******error********/ i++ /*******error*********/ if(n=i) return 1; else return 0; } main() { int a; printf(\nPlease enter data:); scanf(%d,a); if(fun(a)) printf(YES\n); else printf(NO!\n); } 【答案及难度指数】★ i++; (2)if(n==i) 3.请编写函数fun,该函数的功能是:实现D=B+B’,即把矩阵B加上B的转置,存放在矩阵D中。计算结果在main函数中输出。 例如,输入下面的矩阵: 其转置矩阵为: 1 2 3 1 4 7 4 5 6 2 5 8 7 8 9 3 6 9 则程序输出: 2 6 10 6 10 14 10 14 18 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h void fun(int b[3][3],int d[3][3]) { } main() { int b[3][3]={{1,2,3},{4,5,6},{7,8,9}},c[3][3] ; int i,j ; FILE *out; fun(b,c) ; out=(outfile.dat,w); for(i=0 ;i3 ;i++) { for(j=0 ;j3 ;j++) { printf(%7d,c[i][j]) ; fprintf(out,%7d,c[i][j]) ; } printf(\n) ; fprintf(out,\n); } fclose(out); 【答案及难度指数】★★★ int i,j,t[3][3]; for(i=0;i=2;i++) for(j=0;j=2;j++) t[i][j]=b[j][i]; //求逆置 for(i=0;i3;i++) for(j=0;j3;j++) d[i][j]=b[i][j]+t[i][j]; //矩阵与其逆置相加 55 1.请补充fun函数,该函数的功能是:交换数组a中最大和最小两个元素的位置,结果重新保存在原数组中,其他元素位置不变。注意数组a中没有相同元素。 例如,输入20,40,78,60,52,则输出结果为78,40,20,60,52。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 5 void fun(int a[]) { int i,temp; int max=0,min=0; for(i=0;iN;i++) { if(___1___) max=i; if(___2___) min=i; } temp=a[max]; ___3___; a[min]=temp; } main() { int i; int a[N]={20,40,78,60,52}; printf(The original array \n); for(i=0;iN;i++) printf(%4d,a[i]); fun(a); printf(The new array\n); for(i=0;iN;i++) printf(%4d,a[i]); } 【答案及难度指数】★★ (1)a[max]a[i] (2)a[min]a[i] (3)a[max]=a[min] 2.下列给定程序中,函数fun的功能是:利用插入排序法对字符串中的字符按从小到大的顺序进行排序。插入法的基本算法是:先对字符串中的头两个元素进行排序;然后把第三个字符插入到前两个字符中,插入后前三个字符依然有序;再把第四个字符插入到前三个字符中……待排序的字符串已在主函数中赋予。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h # include string.h # define N 100 void getin(char *str) { int i,j,n; char ch; n=strlen(str); for(i=1;in ;i++) { /*******error*********/ c=str[i]; j=i-1; while((j=0) (chstr[j])) { str[j+1]=str[j]; j--; } str[j+1]=ch; } } main() { char s[N]=asdfsdfsdf; printf(The original string : %s\n,s); getin(s); printf(The string after sorting : %s\n\n,s); } 【答案及难度指数】★ ch=str[i]; 3.已知学生的记录由学号和学习成绩构成,M名学生的数据已存入a结构体数组中。请编写函数fun,该函数的功能是:找出成绩最高的学生记录,通过形参返回主函数(规定只有一个最高分)。已给出函数的首部,请完成该函数。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # include string.h # include conio.h # define M 10 typedef struct ss { char num[10]; int s; } SCORE; void fun(SCORE a[],SCORE *s) { } main() { SCORE stu[M]={{02,69},{04,85}, {01,91},{08,64},{06,87},{015,85},{013,91},{012,64},{011,92},{017,64}},n; int i; FILE *out; printf(The original data \n); for(i=0;iM;i++) printf(N0=%s Mark=%d\n,stu[i].num,stu[i].s); fun(stu,n); printf(THE RESULT \n); printf( The high : %s,%d\n,n.num, n.s); out= (outfile.dat,w); fprintf(out,%s\n%d,n.num,n.s); fclose (out); } 【答案及难度指数】★★★ int i,max; max=a[0].s; //初始化min指向第一个成绩 for(i=0;iM;i++) //进入循环,找出最值 if(a[i].smax) //每一个成绩与max较,如果比max大,则进行交换 { max=a[i].s; *s=a[i]; } 54 1.请补充fun函数,该函数的功能是:求100(不包括100)以内能被2或3整除,但不能同时被2和3整除的自然数。结果保存在数组a中,fun函数返回数组a元素的个数。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 100 int fun(int a[]) { int i,j; for(___1___,j=0;i100;i++) if((i%2!=0 i%3==0) || (i%2==0 i%3!=0)) ___2___; ___3___; } main() { int i,n; int a[N]; n=fun(a); for(i=0;in;i++) { if(i%10==0) printf(\n); printf(%4d,a[i]); } } 【答案及难度指数】★★ i=1 (2)a[j++]=i (3)return j 2.下列给定程序中,函数fun的功能是:求n!(n20),所求阶乘的值作为函数值返回。例如,若n=5,则应输出120。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h long fun(int n) { /*******error********/ if n1 return (n*fun(n-1)); return 1; } main() { int n=5; printf(%d!=%ld\n,n,fun(n)); } 【答案及难度指数】★ if(n1) 3.请编写函数fun,其功能是:将str所指字符串中除了下标为奇数、ASCII值也为奇数的字符之外,其余的所有字符都删除,串中剩余字符所形成的一个新串放在s所指的数组中。 例如,若str所指字符串中的内容为ABCDEFG12345,其中字符A的ASCII码值虽为奇数,但所在元素的下标为偶数,因此必需删除;而字符1的ASCII码值为奇数,所在数组中的下标也为奇数,因此不应当删除,其他以此类推。最后s所指的数组中的内容应是135。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include conio.h # include stdio.h # include string.h void fun(char *str,char s[]) { } main() { char str[100],s[100]; FILE *out; printf(\nPlease enter string :); scanf(%s,str); fun(str,s); printf(\nThe result is: %s\n,s); out=(outfile.dat,w); strcpy(str,Please enter string :); fun(str,s); fprintf(out,%s,s); fclose(out); } 【答案及难度指数】★★★ int i,j=0,n; n=strlen(str); for(i=0;in;i++) if(i%2!=0 str[i]%2!=0) //判断字符i是否符合条件 { s[j]=str[i]; j++; } s[j]=‘\0’; 53 1.请补充fun函数,该函数的功能是:把字符下标能被2和3同时整除的字符从字符串s中删除,把剩余的字符重新保存在字符串s中。字符串s从键盘输入,其长度作为参数传入fun函数。 例如,输入abcdefghijk,则输出bcdefhijk。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 100 void fun(char p[],int n) { int i,k; ___1___; for(i=0;in;i++) { p[k++]=p[i]; if((i%2==0) ___2___ (i%3==0)) k--; } ___3___; } main() { int i=0,strlen=0; char s[N]; printf(Please a string:\n); gets(s); while(s[i]!=‘\0’) { strlen++; i++; } fun(s,strlen); printf(The new string\n); puts(s); } 【答案及难度指数】★★ k=0 (2) (3)p[k]=‘\0’ 2.下列给定程序中函数fun的功能是:从低位开始取出长整型变量a中奇数位上的数,依次构成一个新数放在b中,例如,当a中的数为7654321时,则b中的数为7531。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include conio.h # include stdio.h /*******error*********/ void fun(long a,long b) { long s1=10; *b=a%10; while(a0) { a=a/100; *b=a%10*s1+*b; /*******error*********/ s1=s1*100; } } main() { long a,b; printf(\nPlease enter data:); scanf(%ld,a); fun(a,b); printf(The result is: %ld\n,b); } 【答案及难度指数】★★★ (1)void fun(long a,long *b) (2)s1=s1*10; 3.请编写函数fun,该函数的功能是:移动字符串中的请勿改动主函数main与其他函数中的任何); scanf(%d,n); fun(s,n); printf(\nThe string after moving:\n); puts(s); printf(\n\n); out= (outfile.dat,w); fun(s,strlen(s)-n); fun(s,3); fprintf(out,%s,s); fclose (out); } 【答案及难度指数】★★★★ char b[M]; int i,j=0; for(i=0;in;i++) //将str中下标为0~n的值复制到b { b[j]=str[i]; j++; } for(i=0;istrlen(str)-n;i++) //将从下标n的字符开始前移 str[i]=str[i+n]; for(j=0;jn;j++) //将b中下标由0~n的字符复制到str { str[i]=b[j]; i++; } str[i]=‘\0’; 52 1.从键盘输入一组小写字母,保存在字符数组str中。请补充fun函数,该函数的功能是:把字符数组str中字符下标为偶数的小写字母转换成对应的大写字母,结果仍保存在原数组中。 例如,输入asdfghj,则输出AsDfGhJ。 请勿改动主函数main与其他函数中的任何内容,仅在fun函数的横线上填写所需的若干表达式或语句。 注意:部分源程序给出如下。 # include stdio.h # define N 100 void fun(char s[]) { int j=0; while(___1___) { if(j%2==0) s[j]-=___2___; ___3___; } } main() { char str[N]; printf(Please a string: \n); gets(str); printf(The original string \n); puts(str); fun(str); printf(The new string\n); puts(str); } 【答案及难度指数】★★ s[j]!=‘\0’ (2)32 (3)j++ 2.下列给定程序中,函数fun的功能是:将字符串p中的所有字符复制到字符串a中,要求每复制三个字符之后插入一个空格。例如,在调用fun函数之前给字符串s输入asdf,调用函数之后,字符串a中的内容则为asd f。 请修改程序中的错误,得出正确的结果。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。 # include stdio.h void fun(char *p,char *a) { int i,j=0; while(*p) { /*******error*********/ i=1; /*******error*********/ while(i3 || *p) { a[j]=*p; j++; p++; i++; } /*******error********/ if(*p) a[j]=‘ ‘; } a[j]=‘\0’; } main() { char s[80],a[80]; printf(Enter a string: ); gets(s); printf(The original string: ); puts(s); fun(s,a); printf(\nThe string after insert space: ); puts(a); printf(\n\n); } 【答案及难度指数】★★★ (1)i=0; (2)while(i3 *p) (3)a[j++]=‘ ‘; 3.请编写函数fun,该函数的功能是:移动一维数组中的内容;若数组中有m个整数,要求把下标从0到t(t≤m-1)的数组元素平移到数组的最后。 例如,一维数组中的原始内容为:1,2,3,4,5,6,7,8,9,10;t的值为3。移动后,一维数组中的内容应为:5,6,7,8,9,10,1,2,3,4。 请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 注意:部分源程序给出如下。 # include stdio.h # define M 100 void fun(int *s,int t,int m) { } main() { int str[M]={1,2,3,4,5,6,7,8,9,10}; int i,t,n=10; FILE *out; int test[M]={1,1,2,3,5,8,13,21, 34,55,89,144}; printf(The original data:\n); for(i=0;in;i++) printf(%3d,str[i]); printf(\n\nEnter t: ); scanf(%d,t); fun(str,t,n); printf(\nThe data after moving :\n); for(i=0;in;i++) printf(%3d,str[i]); printf(\n\n); out=(outfile.dat,w); fun(test,6,12); for(i=0;i12;i++) fprintf(out,%d\n,test[i]); fclose(out); } 【答案及难度指数】★★★★ int a[M],i,j=0; for(i=0;i=t;i++) //将数组s备份到临时数组a a[i]=s[i]; for(i=t+1;im;i++) //从指定下标的下一个元素t+1开始,前移 { s[j]=s[i]; j++; } for(i=0;i=t;i++) //接着拷贝a中的前t个元素 { s[j]=a[i]; j++; }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值