eatc.cn4月上机考试题库填空 double fur #include <stdio h> i int i,j, double S, av, yIN; #include <string. h> #define n 5 for(F0, K<N; 1+) s=S+x[ #define m 8 /**布布亭枣事 found布亭事事事*/ int fun(char (ss)[M), char av- i int 1, for(i==0,KN,计+) /率事事事率 found*事亭率事事事事率率/ if( xian for(r=0,i<_1,i++) 率*布率率事事布 found布率率事事摩*/ 事事半布市事率 tremp(ssi, tF0) /**事事率率 found事事事*/ if(x[=_3 ++]=x[ maino for(=0,iN,计+=y[, f char chINIIMEI if,"while", switch","int',"for"), tM intf("uThe original string nIn"); maino for(F0; i <N; i++)puts(ch(): printf("n); double xN: printf("n Enter a string for search: ") gets(t); for(F0; K<N; i++) x[i=rando%50: printf("%4.0f" x); 3 =fun(ch, t) rinf("\n") 率布事事事事布事 found市事事率本事事事率/ printf("nThe average is: %f\n", fun(x)); intf("lnDon't found! n") rinf("\nThe result: \n", fun(x)) else printf("nThe position is %d\n", n); for(=0,i<N,计+) printf("%s.0f",x可 20、给定程序中,函数fun的功能是:找出N×N矩阵中每 列元素中的最大值,并按顺序依次存放于形参b所指的一维 18、给定程序 数fun的功能是:计算出形参s所指字数组中 符串中包含的单词个数作为函数值返回。为便于统计,规 清在程序的下划线处填入正确的内容并把下划线删除 定各单词之间用空格隔开 使程序得出正确的结果 例如,形参s所指的字符串为: This is a C 注意:源程序存放在考生文件夹下的 BLANKLC中 rogram,函数的返回值为6。 不得增行或删行,也不得更改程序的结构! 清在程序的下划线处填入正确的内容并把下划线删除,# include< stdio h> 使程序得出正确的结果 #define n 4 注意:源程序存放在考生文件夹下的 BLANKIO中 void fun(int(°a[N],int·b) 不得增行或删行,也不得更改程序的结构! #include <stdio. h> for(F=0,i<N;计++){ bOF for(F1; j<N; j++) i if(s!='&& flag==0)i /率布率春事 found布率率布率*/ 率*布亭事率率 found事事事*率事事市/ if(b2 adlo b=anIo 冰率*布事率事事布 found布春亭率布摩/ ifs==) maino /率率布率事布fnd事本亭事率/ xNN={{12,5.8,7},{6,1,9,3},{1,2,3,4},{2,84,3}}yN]j printf("nThe matrix: n"); for(F=0,i<N,计++) i for(F0; j <N; j++) printf("%4d"[: maino int n printf("eNter a line text: n"); gets(str); /率事事率布事 found市事事率*事率*/ n=fun(str) printf("n There are %d words in this text. nn,n); printf("nThe result is: ) for(F0; K<N; i++) printf("%3d",y) printf("n") 19、给定程序中,函数fun的功能是:在形参ss所指字 串数组中查找与形参t所指字符串相同的串,找到后返回该 串在字符串数组中的位置(下标值),未找到则返回1。s21、给定程序中,函数fun的功能是:判断形参s所指字符 所指字符串数组中共有N个内容不同的字符串,且串长小串是否是回文”( Palindrome),若是,函数返回值为1:不 于M。 是,函数返回值为0。"回文"是正读和反读都一样的字符串 请在程序的下划线处填入正确的内容并把下划线删 (不区分大小写字母) 使程序得出正确的结果 例如, LEVEL和Leve是"回文",而 LEVLEV不是 注意:源程序存放在考生文件夹下的 BLANK1C中 回文”。 不得增行或删行,也不得更改程序的结构! 请在程序的下划线处填入正确的内容并把下划线删除
宏为世纪教育 www.greatc.cn 4 月上机考试题库 填空题 6 double fun(double *x) { int i, j; double s, av, y[N]; s=0; for(i=0; i<N; i++) s=s+x[i]; /**********found**********/ av=__1__; for(i=j=0; i<N; i++) if( x[i]>av ){ /**********found**********/ y[__2__]=x[i]; x[i]=-1;} for(i=0; i<N; i++) /**********found**********/ if( x[i]!= __3__) y[j++]=x[i]; for(i=0; i<N; i++)x[i] = y[i]; return av; } main() { int i; double x[N]; for(i=0; i<N; i++){ x[i]=rand()%50; printf("%4.0f ",x[i]);} printf("\n"); printf("\nThe average is: %f\n",fun(x)); printf("\nThe result :\n",fun(x)); for(i=0; i<N; i++) printf("%5.0f ",x[i]); printf("\n"); } 18、给定程序中,函数 fun 的功能是:计算出形参 s 所指字 符串中包含的单词个数,作为函数值返回。为便于统计,规 定各单词之间用空格隔开。 例如,形参 s 所指的字符串为:This is a C language program.,函数的返回值为 6。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! #include <stdio.h> int fun(char *s) { int n=0, flag=0; while(*s!='\0') { if(*s!=' ' && flag==0) { /**********found**********/ __1__ ; flag=1;} /**********found**********/ if (*s==' ') flag= __2__ ; /**********found**********/ __3__ ; } return n; } main() { char str[81]; int n; printf("\nEnter a line text:\n"); gets(str); n=fun(str); printf("\nThere are %d words in this text.\n\n",n); } 19、给定程序中,函数 fun 的功能是:在形参 ss 所指字符 串数组中查找与形参 t 所指字符串相同的串,找到后返回该 串在字符串数组中的位置(下标值),未找到则返回-1。ss 所指字符串数组中共有 N 个内容不同的字符串,且串长小 于 M。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! #include <stdio.h> #include <string.h> #define N 5 #define M 8 int fun(char (*ss)[M],char *t) { int i; /**********found**********/ for(i=0; i< __1__ ; i++) /**********found**********/ if(strcmp(ss[i],t)==0 ) return __2__ ; return -1; } main() { char ch[N][M]={"if","while","switch","int","for"},t[M]; int n,i; printf("\nThe original string\n\n"); for(i=0;i<N;i++)puts(ch[i]); printf("\n"); printf("\nEnter a string for search: "); gets(t); n=fun(ch,t); /**********found**********/ if(n== __3__) printf("\nDon't found!\n"); else printf("\nThe position is %d .\n",n); } 20、给定程序中,函数 fun 的功能是:找出 N×N 矩阵中每 列元素中的最大值,并按顺序依次存放于形参 b 所指的一维 数组中。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! #include <stdio.h> #define N 4 void fun(int (*a)[N], int *b) { int i,j; for(i=0; i<N; i++) { /**********found**********/ b[i]= __1__; for(j=1; j<N; j++) /**********found**********/ if(b[i] __2__ a[j][i]) b[i]=a[j][i]; } } main() { int x[N][N]={ {12,5,8,7},{6,1,9,3},{1,2,3,4},{2,8,4,3} },y[N],i,j; printf("\nThe matrix :\n"); for(i=0;i<N; i++) { for(j=0;j<N; j++) printf("%4d",x[i][j]); printf("\n"); } /**********found**********/ fun(__3__); printf("\nThe result is:"); for(i=0; i<N; i++) printf("%3d",y[i]); printf("\n"); } 21、给定程序中,函数 fun 的功能是:判断形参 s 所指字符 串是否是"回文"(Palindrome),若是,函数返回值为 1;不 是,函数返回值为 0。"回文"是正读和反读都一样的字符串 (不区分大小写字母)。 例如,LEVEL 和 Level 是"回文",而 LEVLEV 不是" 回文"。 请在程序的下划线处填入正确的内容并把下划线删除
宏为世纪教育www.great4月上机考试题库填空是 使程序得出正确的结果 10004," FangFang",90,82,8 注意:源程序存放在考生文件夹下的 BLANKl.C中 10005," ZhangSan",95,80,88},ssN] 不得增行或删行,也不得更改程序的结构! FILE·fp #include <stdio. h> fp= fopen("student. dat","wb #include <string h> # include <ctype.h> iclose(fp) int fun( char *s) printf("nThe original data: n"); char *Ip,’p fp= fopen("student. dat","rb"); /**布率事布 found事事事事*/ fread(ss, sizeof(STU), N, fp); while(( toupper(IpF=toupper(rp))&&(lp<rp))i i printf("nNo: %ld Name: %-8s 率率布布率率布 found*春枣亭事率事摩率 ss[. sno, ss0 name); for(F0; K<3: 1++)printf("%6.2f", ss0. score[]); printf("\n") if(lp<rp) 3 else return I fun("student. dat", 10003); fp= fopen("student. dat", "rb") maino ead( ss, sizeof(STU), N, fp); f char s[81; iclose(fp); printf("Enter a string: ) scanf("%s printf("unThe data after modifing \n"); if(fun(s) printf("n"%s\"is a Palindrome. nin"s); for(=0,j<N;++) else printf("\n"%s"isnt a Palindrome. \nin"S); i printf("unNo: %ld Name: %-8s ,ss0 sno, sson for(=0,3;,计++) printf("%6.2f",sbi] score回 2、程序通过定义学生结构体变量存储了学生的学号 printi("n") 名和3门课的成绩。所有学生数据均以二进制方式输出到} student dat文件中。函数fun的功能是从指定文件中找出指} 定学号的学生数据,读入此学生数据,对该生的分数进行修 改,使每门课的分数加3分,修改后重写文件中该学生的数23、程序通过定义学生结构体变量,存储了学生的学号、姓 据,即用该学生的新数据覆盖原数据,其它学生数据不变:名和3门课的成绩。函数fun的功能是对形参b所指结构体 若找不到,则什么都不做 变量中的数据进行修改,最后在主函数中输出修改后的数 请在程序的下划线处填入正确的内容并把下划线删除,据 使程序得出正确的结果 例如:b所指变量t中的学号、姓名、和三门课的成绩依 注意:源程序存放在考生文件夹下的 BLANKI.C中 次是:10002、 Zhang"、93、85、87,修改后输出t中的 不得增行或删行,也不得更改程序的结构! 数据应为:10004、" LiJie"、93、85、87 #include <stdio. h> 请在程序的下划线处填入正确的内容并把下划线删除 #define n 5 使程序得出正确的结果 typedef struct student 注意:源程序存放在考生文件夹下的 BLANKLC中。 不得增行或删行,也不得更改程序的结构! char name[ 10]; #include <stdio. h> float score3]; #include <string. h A STU struct student i void fun( char *filename, long sno) long sno, STU n float score3]: 率*布事率布布 found布事率率布事率*/ void fun( struct student *b) while(feof(I)) f in i fread( &n, sizeof(STU), 1, fp); /率春率率布摩 found*事率率事**/ if(nsno 2 sno) if (I feof(fp)) for(F=0;κ<3;计++)n. score[+=3 /**布事率率布foun i struct student t( 10002, "Zhang Q1,93, 85,; 3, -1(long)sizeof(STU), SEEK CUR); fwrite( &n, sizeof(STU), 1, fp); printf("nln The original data n"); printf("nNo: %ld Name: %snScores: " tsno, tname); fclose(fp) for(F0; K <3: 1++) printi(%6.2f",t. D: STU tIN}={{10001, Macha",91,92,77} fun(3_), {10002," Caokai",75,60,88} printf("nThe data after modified: n"); 10003,"Ls, printf("\nNo: %ld Name: %slnScores: ", tsno, tname);
宏为世纪教育 www.greatc.cn 4 月上机考试题库 填空题 7 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! #include <stdio.h> #include <string.h> #include <ctype.h> int fun(char *s) { char *lp,*rp; /**********found**********/ lp= __1__ ; rp=s+strlen(s)-1; while((toupper(*lp)==toupper(*rp)) && (lp<rp) ) { /**********found**********/ lp++; rp __2__ ; } /**********found**********/ if(lp<rp) __3__ ; else return 1; } main() { char s[81]; printf("Enter a string: "); scanf("%s",s); if(fun(s)) printf("\n\"%s\" is a Palindrome.\n\n",s); else printf("\n\"%s\" isn't a Palindrome.\n\n",s); } 22、程序通过定义学生结构体变量,存储了学生的学号、姓 名和 3 门课的成绩。所有学生数据均以二进制方式输出到 student.dat 文件中。函数 fun 的功能是从指定文件中找出指 定学号的学生数据,读入此学生数据,对该生的分数进行修 改,使每门课的分数加 3 分,修改后重写文件中该学生的数 据,即用该学生的新数据覆盖原数据,其它学生数据不变; 若找不到,则什么都不做。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! #include <stdio.h> #define N 5 typedef struct student { long sno; char name[10]; float score[3]; } STU; void fun(char *filename, long sno) { FILE *fp; STU n; int i; fp = fopen(filename,"rb+"); /**********found**********/ while (!feof(__1__)) { fread(&n, sizeof(STU), 1, fp); /**********found**********/ if (n.sno__2__sno) break; } if (!feof(fp)) { for (i=0; i<3; i++) n.score[i] += 3; /**********found**********/ fseek(__3__, -1(long)*sizeof(STU), SEEK_CUR); fwrite(&n, sizeof(STU), 1, fp); } fclose(fp); } main() { STU t[N]={ {10001,"MaChao", 91, 92, 77}, {10002,"CaoKai", 75, 60, 88}, {10003,"LiSi", 85, 70, 78}, {10004,"FangFang", 90, 82, 87}, {10005,"ZhangSan", 95, 80, 88}}, ss[N]; int i,j; FILE *fp; fp = fopen("student.dat", "wb"); fwrite(t, sizeof(STU), N, fp); fclose(fp); printf("\nThe original data :\n"); fp = fopen("student.dat", "rb"); fread(ss, sizeof(STU), N, fp); fclose(fp); for (j=0; j<N; j++) { printf("\nNo: %ld Name: %-8s Scores: ",ss[j].sno, ss[j].name); for (i=0; i<3; i++) printf("%6.2f ", ss[j].score[i]); printf("\n"); } fun("student.dat", 10003); fp = fopen("student.dat", "rb"); fread(ss, sizeof(STU), N, fp); fclose(fp); printf("\nThe data after modifing :\n"); for (j=0; j<N; j++) { printf("\nNo: %ld Name: %-8s Scores: ",ss[j].sno, ss[j].name); for (i=0; i<3; i++) printf("%6.2f ", ss[j].score[i]); printf("\n"); } } 23、程序通过定义学生结构体变量,存储了学生的学号、姓 名和 3 门课的成绩。函数 fun 的功能是对形参 b 所指结构体 变量中的数据进行修改,最后在主函数中输出修改后的数 据。 例如: b 所指变量 t 中的学号、姓名、和三门课的成绩依 次是: 10002、"ZhangQi"、93、85、87,修改后输出 t 中的 数据应为:10004、" LiJie "、93、85、87。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1.C 中。 不得增行或删行,也不得更改程序的结构! #include <stdio.h> #include <string.h> struct student { long sno; char name[10]; float score[3]; }; void fun( struct student *b) { int i; /**********found**********/ b__1__ = 10004; /**********found**********/ strcpy(b__2__, "LiJie"); } main() { struct student t={10002,"ZhangQi", 93, 85, 87}; int i; printf("\n\nThe original data :\n"); printf("\nNo: %ld Name: %s\nScores: ",t.sno, t.name); for (i=0; i<3; i++) printf("%6.2f ", t.score[i]); printf("\n"); /**********found**********/ fun(__3__); printf("\nThe data after modified :\n"); printf("\nNo: %ld Name: %s\nScores: ",t.sno, t.name);