为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > C语言程序填空题

C语言程序填空题

2017-10-13 50页 doc 188KB 74阅读

用户头像

is_833902

暂无简介

举报
C语言程序填空题C语言程序填空题 一、填空题 考试做题要求:1、在__1__处填写正确的答案,并将下划线和数字删除。 2、将题目做完之后一定要保存。3、不能删除 /**********found**********/,也不能多行或少行。 1、给定程序中,函数fun的功能是根据形参i的值返回某个函数的值。当调用正确时, 程序输出: x1=5.000000, x2=3.000000, x1*x1+x1*x2=40.000000 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BL...
C语言程序填空题
C语言程序填空题 一、填空题 考试做题:1、在__1__处填写正确的答案,并将下划线和数字删除。 2、将题目做完之后一定要保存。3、不能删除 /**********found**********/,也不能多行或少行。 1、给定程序中,函数fun的功能是根据形参i的值返回某个函数的值。当调用正确时, 程序输出: x1=5.000000, x2=3.000000, x1*x1+x1*x2=40.000000 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include double f1(double x) { return x*x; } double f2(double x, double y) { return x*y; } /**********found**********/ __1__ fun(int i, double x, double y) { if (i==1) /**********found**********/ return __2__(x); else /**********found**********/ return __3__(x, y); } main() { double x1=5, x2=3, r; r = fun(1, x1, x2); r += fun(2, x1, x2); printf("\nx1=%f, x2=%f, x1*x1+x1*x2=%f\n\n",x1, x2, r); } 2、程序通过定义学生结构体数组,存储了若干名学生的学号、姓名和3门课的成绩。函数fun的功能是将存放学生数据的结构体数组,按 照姓名的字典序(从小到大)排序。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include struct student { long sno; char name[10]; float score[3]; }; void fun(struct student a[], int n) { /**********found**********/ __1__ t; 1 int i, j; /**********found**********/ for (i=0; i<__2__; i++) for (j=i+1; j 0) { t = a[i]; a[i] = a[j]; a[j] = t; } } main() { struct student s[4]={{10001,"ZhangSan", 95, 80, 88}, {10002,"LiSi", 85, 70, 78}, {10003,"CaoKai", 75, 60, 88}, {10004,"FangFang", 90, 82, 87}}; int i, j; printf("\n\nThe original data :\n\n"); for (j=0; j<4; j++) { printf("\nNo: %ld Name: %-8s Scores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf("\n"); } fun(s, 4); printf("\n\nThe data after sorting :\n\n"); for (j=0; j<4; j++) { printf("\nNo: %ld Name: %-8s Scores: ",s[j].sno, s[j].name); for (i=0; i<3; i++) printf("%6.2f ", s[j].score[i]); printf("\n"); } } 3、给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(所有数均为正数),作为函数值返回;并将大于平均值 的数放在形参y所指数组中,在主函数中输出。 例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000 主函数中输出:46 32 40 45 48 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #define N 10 double fun(double x[],double *y) { int i,j; double av; /**********found**********/ av=__1__; /**********found**********/ for(i=0; iav) y[__3__]= x[i]; y[j]=-1; return av; } main() { int i; double x[N],y[N]; for(i=0; i=0; i++) printf("%5.1f ",y[i]); printf("\n"); } 4、给定程序中,函数fun的功能是:将a所指4×3矩阵中第k行的元素与第0行元素交换。 例如,有下列矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 若k为2,程序执行结果为: 7 8 9 4 5 6 1 2 3 10 11 12 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #define N 3 #define M 4 /**********found**********/ void fun(int (*a)[N], int __1__) { int i,j,temp ; /**********found**********/ for(i = 0 ; i < __2__ ; i++) { temp=a[0][i] ; /**********found**********/ a[0][i] = __3__ ; a[k][i] = temp ; } } main() { int x[M][N]={ {1,2,3},{4,5,6},{7,8,9},{10,11,12} },i,j; printf("The array before moving:\n\n"); 3 for(i=0; i #include #include #define N 9 long ctod( char *s ) { long d=0; while(*s) if(isdigit( *s)) { /**********found**********/ d=d*10+*s-__1__; /**********found**********/ __2__; } return d; } long fun( char *a, char *b ) { /**********found**********/ return __3__; } main() { char s1[N],s2[N]; do { printf("Input string s1 : "); gets(s1); } while( strlen(s1)>N ); do { printf("Input string s2 : "); gets(s2); } while( strlen(s2)>N ); 4 printf("The result is: %ld\n", fun(s1,s2) ); } 6、给定程序中,函数fun的功能是:计算下式前n项的和作为函数值返回。 例如,当形参n的值为10时,函数返回:9.612558。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include double fun(int n) { int i; double s, t; /**********found**********/ s=__1__; /**********found**********/ for(i=1; i<=__2__; i++) { t=2.0*i; /**********found**********/ s=s+(2.0*i-1)*(2.0*i+1)/__3__; } return s; } main() { int n=-1; while(n<0) { printf("Please input(n>0): "); scanf("%d",&n); } printf("\nThe result is: %f\n",fun(n)); } 7、给定程序中,函数fun的功能是:在3×4的矩阵中找出在行上最大、在列上最小的那个元素,若没有符合条件的元素则输出相应信息。 例如,有下列矩阵: 1 2 13 4 7 8 10 6 3 5 9 7 程序执行结果为:find: a[2][2]=9 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ 5 #include #define M 3 #define N 4 void fun(int (*a)[N]) { int i=0,j,find=0,rmax,c,k; while( (i #include #define N 5 #define M 10 6 int fun(char (*ss)[M], int k) { int i,j=0,len; /**********found**********/ for(i=0; i< __1__ ; i++) { len=strlen(ss[i]); /**********found**********/ if(len<= __2__) /**********found**********/ strcpy(ss[j++],__3__); } return j; } main() { char x[N][M]={"Beijing","Shanghai","Tianjing","Nanjing","Wuhan"}; int i,f; printf("\nThe original string\n\n"); for(i=0;i #include struct student { long sno; char name[10]; float score[3]; }; void fun(struct student a) { struct student b; int i; /**********found**********/ b = __1__; b.sno = 10002; /**********found**********/ strcpy(__2__, "LiSi"); printf("\nThe data after modified :\n"); printf("\nNo: %ld Name: %s\nScores: ",b.sno, b.name); /**********found**********/ 7 for (i=0; i<3; i++) printf("%6.2f ", b.__3__); printf("\n"); } main() { struct student s={10001,"ZhangSan", 95, 80, 88}; int i; printf("\n\nThe original data :\n"); printf("\nNo: %ld Name: %s\nScores: ",s.sno, s.name); for (i=0; i<3; i++) printf("%6.2f ", s.score[i]); printf("\n"); fun(s); } 10、给定程序中,函数fun的功能是:在形参ss所指字符串数组中,将所有串长超过k的字符串中右边的字符删除,只保留左边的k个字 符。ss所指字符串数组中共有N个字符串,且串长小于M。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include #define N 5 #define M 10 /**********found**********/ void fun(char (*ss) __1__, int k) { int i=0 ; /**********found**********/ while(i< __2__) { /**********found**********/ ss[i][k]=__3__; i++; } } main() { char x[N][M]={"Create","Modify","Sort","skip","Delete"}; int i; printf("\nThe original string\n\n"); for(i=0;i #include #define N 80 void fun(char *s, int n, char *t) { int len,i,j=0; len=strlen(s); /**********found**********/ if(n>=len) strcpy(__1__); else { /**********found**********/ for(i=len-n; i<=len-1; i++) t[j++]= __2__ ; /**********found**********/ t[j]= __3__ ; } } main() { char s[N],t[N]; int n; printf("Enter a string: ");gets(s); printf( "Enter n:"); scanf("%d",&n); fun(s,n,t); printf("The string t : "); puts(t); } 12、给定程序中,函数fun的功能是:将形参s所指字符串中的所有数字字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作 为函数值返回。 例如,s所指字符串为:asd123fgh5##43df, 处理后新字符串为:123543asdfgh##df。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include #include #include char *fun(char *s) { int i, j, k, n; char *p, *t; n=strlen(s)+1; t=(char*)malloc(n*sizeof(char)); p=(char*)malloc(n*sizeof(char)); j=0; k=0; for(i=0; i fun(int x) { int n, s1, s2, s3, t; n=0; t=100; /**********found**********/ while(t<=__1__){ /**********found**********/ s1=t%10; s2=(__2__)%10; s3=t/100; /**********found**********/ if(s1+s2+s3==__3__) { printf("%d ",t); n++; } t++; } return n; } main() { int x=-1; while(x<0) { printf("Please input(x>0): "); scanf("%d",&x); } printf("\nThe result is: %d\n",fun(x)); 10 } 14、给定程序中,函数fun的功能是:将形参s所指字符串中的数字字符转换成对应的数值,计算出这些数值的累加和作为函数值返回。 ?例如,形参s所指的字符串为:abs5def126jkm8,程序执行后的输出结果为:22。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include #include int fun(char *s) { int sum=0; while(*s) { /**********found**********/ if( isdigit(*s) ) sum+= *s- __1__ ; /**********found**********/ __2__; } /**********found**********/ return __3__ ; } main() { char s[81]; int n; printf("\nEnter a string:\n\n"); gets(s); n=fun(s); printf("\nThe result is: %d\n\n",n); } 15、给定程序中,函数fun的功能是将带头节点的单向链结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为: 10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include #define N 6 typedef struct node { int data; struct node *next; } NODE; void fun(NODE *h) { NODE *p, *q; int t; /**********found**********/ p = __1__ ; while (p) { 11 /**********found**********/ q = __2__ ; while (q) { /**********found**********/ if (p->data __3__ q->data) { t = p->data; p->data = q->data; q->data = t; } q = q->next; } p = p->next; } } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h = (NODE *)malloc(sizeof(NODE)); h->next = NULL; for(i=0; idata=a[i]; q->next = NULL; if (h->next == NULL) h->next = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p = h->next; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() { NODE *head; int a[N]= {0, 10, 4, 2, 8, 6 }; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); fun(head); printf("\nThe list after sorting :\n"); outlist(head); 12 } 16、程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。函数fun的功能是将形参a所指结构体变量s中的数据进 行修改,并把a中地址作为函数值返回主函数,在主函数中输出修改后的数据。 例如:a所指变量s中的学号、姓名、和三门课的成绩依次是:10001、" ZhangSan "、95、80、88,修改后输出t中的数据应为:10002、 "LiSi "、96、81、89。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include struct student { long sno; char name[10]; float score[3]; }; /**********found**********/ __1__ fun(struct student *a) { int i; a->sno = 10002; strcpy(a->name, "LiSi"); /**********found**********/ for (i=0; i<3; i++) __2__ += 1; /**********found**********/ return __3__ ; } main() { struct student s={10001,"ZhangSan", 95, 80, 88}, *t; int i; printf("\n\nThe original data :\n"); printf("\nNo: %ld Name: %s\nScores: ",s.sno, s.name); for (i=0; i<3; i++) printf("%6.2f ", s.score[i]); printf("\n"); t = fun(&s); nThe data after modified :\n"); printf("\ printf("\nNo: %ld Name: %s\nScores: ",t->sno, t->name); for (i=0; i<3; i++) printf("%6.2f ", t->score[i]); printf("\n"); } 17、给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中大于平均值的数据移 至数组的前部,小于等于平均值的数据移至x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。 例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000 移动后的输出为:46 32 40 45 48 30 6 17 15 26 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 13 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include #define N 10 double fun(double *x) { int i, j; double s, av, y[N]; s=0; for(i=0; iav ){ /**********found**********/ y[__2__]=x[i]; x[i]=-1;} for(i=0; i int fun(char *s) { int n=0, flag=0; while(*s!='\0') { if(*s!=' ' && flag==0) { /**********found**********/ __1__ ; flag=1;} /**********found**********/ 14 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 #include #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 #define N 4 void fun(int (*a)[N], int *b) { int i,j; for(i=0; i string.h> #include < #include int fun(char *s) { char *lp,*rp; /**********found**********/ lp= __1__ ; rp=s+strlen(s)-1; while((toupper(*lp)==toupper(*rp)) && (lp #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]; 17 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 #include 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"); 18 } 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); for (i=0; i<3; i++) printf("%6.2f ", t.score[i]); printf("\n"); } 24、给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中小于平均值的数据移 至数组的前部,大于等于平均值的数据移至x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。 例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000 移动后的输出为:30 6 17 15 26 46 32 40 45 48 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include #define N 10 double fun(double *x) { int i, j; double av, y[N]; av=0; /**********found**********/ for(i=0; i double fun(double e) { int i; double s, x; /**********found**********/ s=0; i=__1__; x=1.0; while(x>e){ /**********found**********/ __2__; /**********found**********/ x=(2.0*i-1)/((__3__)*(2.0*i)); s=s+x; } return s; } main() { double e=1e-3; printf("\nThe result is: %f\n",fun(e)); } 20 26、给定程序中,函数fun的功能是建立一个N×N的矩阵。 矩阵元素的构成规律是:最外层元素的值全部为1;从外向内第2层元素的值 全部为2;第3层元素的值全部为3,…依次类推。例如,若N=5,生成的矩阵为: 1 1 1 1 1 1 2 2 2 1 1 2 3 2 1 1 2 2 2 1 1 1 1 1 1 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #define N 7 /**********found**********/ void fun(int (*a) __1__) { int i,j,k,m; if(N%2==0) m=N/2 ; else m=N/2+1; for(i=0; i double f1(double x) 21 { return x*x; } double f2(double x, double y) { return x*y; } double fun(double a, double b) { /**********found**********/ __1__ (*f)(); double r1, r2; /**********found**********/ f = __2__ ; /* point fountion f1 */ r1 = f(a); /**********found**********/ f = __3__ ; /* point fountion f2 */ r2 = (*f)(a, b); return r1 + r2; } main() { double x1=5, x2=3, r; r = fun(x1, x2); printf("\nx1=%f, x2=%f, x1*x1+x1*x2=%f\n",x1, x2, r); } 28、给定程序中,函数fun的功能是将参数给定的字符串、整数、浮点数写到文本文件中,再用字符串方式从此文本文件中逐个读入,并调 用库函数atoi和atof将字符串转换成相应的整数、浮点数,然后将其显示在屏幕上。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include void fun(char *s, int a, double f) { /**********found**********/ __1__ fp; char str[100], str1[100], str2[100]; int a1; double f1; fp = fopen("file1.txt", "w"); fprintf(fp, "%s %d %f\n", s, a, f); /**********found**********/ __2__ ; fp = fopen("file1.txt", "r"); /**********found**********/ fscanf(__3__,"%s%s%s", str, str1, str2); fclose(fp); a1 = atoi(str1); f1 = atof(str2); 22 printf("\nThe result :\n\n%s %d %f\n", str, a1, f1); } main() { char a[10]="Hello!"; int b=12345; double c= 98.76; fun(a,b,c); } 29、给定程序中,函数fun的功能是:计算下式前n项的和作为函数值返回。 例如,当形参n的值为10时,函数返回:-0.204491。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include double fun(int n) { int i, k; double s, t; s=0; /**********found**********/ k=__1__; for(i=1; i<=n; i++) { /**********found**********/ t=__2__; s=s+k*(2*i-1)*(2*i+1)/(t*t); /**********found**********/ k=k*__3__; } return s; } main() { int n=-1; while(n<0) { printf("Please input(n>0): "); scanf("%d",&n); } printf("\nThe result is: %f\n",fun(n)); } 30、程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。所有学生数据均以二进制方式输出到文件中。函数fun的 功能是重写形参filename所指文件中最后一个学生的数据,即用新的学生数据覆盖该学生原来的数据,其它学生的数据不变。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 23 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #define N 5 typedef struct student { long sno; char name[10]; float score[3]; } STU; void fun(char *filename, STU n) { FILE *fp; /**********found**********/ fp = fopen(__1__, "rb+"); /**********found**********/ fseek(__2__, -(long)*sizeof(STU), SEEK_END); /**********found**********/ fwrite(&n, sizeof(STU), 1, __3__); 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}}; STU n={10006,"ZhaoSi", 55, 70, 68}, ss[N]; int i,j; FILE *fp; fp = fopen("student.dat", "wb"); fwrite(t, sizeof(STU), N, fp); fclose(fp); fp = fopen("student.dat", "rb"); fread(ss, sizeof(STU), N, fp); fclose(fp); printf("\nThe original data :\n\n"); for (j=0; j #define N 10 double fun(double x[],double *av) { int i,j; double d,s; s=0; for(i=0; i void fun(char *s, int a, double f) { 25 /**********found**********/ __1__ fp; char ch; fp = fopen("file1.txt", "w"); fprintf(fp, "%s %d %f\n", s, a, f); fclose(fp); fp = fopen("file1.txt", "r"); printf("\nThe result :\n\n"); ch = fgetc(fp); /**********found**********/ while (!feof(__2__)) { /**********found**********/ putchar(__3__); ch = fgetc(fp); } putchar('\n'); fclose(fp); } main() { char a[10]="Hello!"; int b=12345; double c= 98.76; fun(a,b,c); } 33、程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。函数fun的功能是将形参a中的数据进行修改,把修改后的 数据作为函数值返回主函数进行输出。 例如:传给形参a的数据中,学号、姓名、和三门课的成绩依次是:10001、"ZhangSan"、95、80、88,修改后的数据应为:10002、 "LiSi"、96、81、89。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include struct student { long sno; char name[10]; float score[3]; }; /**********found**********/ __1__ fun(struct student a) { int i; a.sno = 10002; /**********found**********/ strcpy(__2__, "LiSi"); /**********found**********/ for (i=0; i<3; i++) __3__+= 1; return a; 26 } main() { struct student s={10001,"ZhangSan", 95, 80, 88}, t; int i; printf("\n\nThe original data :\n"); printf("\nNo: %ld Name: %s\nScores: ",s.sno, s.name); for (i=0; i<3; i++) printf("%6.2f ", s.score[i]); printf("\n"); t = fun(s); printf("\nThe data after modified :\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"); } 34、给定程序中,函数fun的功能是:利用指针数组对形参ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss 所指字符串数组中共有N个字符串,且串长小于M。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include #define N 5 #define M 8 void fun(char (*ss)[M]) { char *ps[N],*tp; int i,j,k; for(i=0; i #include #include char *fun(char *s) { int i, j, k, n; char *p, *t; n=strlen(s)+1; t=(char*)malloc(n*sizeof(char)); p=(char*)malloc(n*sizeof(char)); j=0; k=0; for(i=0; i='a')&&(s[i]<='z'))||((s[i]>='A')&&(s[i]<='Z'))) { /**********found**********/ t[j]=__1__; j++;} else { p[k]=s[i]; k++; } } /**********found**********/ for(i=0; i<__2__; i++) t[j+i]=p[i]; /**********found**********/ t[j+k]= __3__; return t; } main() { char s[80]; printf("Please input: "); scanf("%s",s); printf("\nThe result is: %s\n",fun(s)); } 36、 例如:若形参e的值为1e-3,函数的返回值为0.551690。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 28 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include double fun(double e) { int i, k; double s, t, x; s=0; k=1; i=2; /**********found**********/ x=__1__/4; /**********found**********/ while(x __2__ e) { s=s+k*x; k=k* (-1); t=2*i; /**********found**********/ x=__3__/(t*t); i++; } return s; } main() { double e=1e-3; printf("\nThe result is: %f\n",fun(e)); } 37、给定程序中,函数fun的功能是:将形参n所指变量中,各位上为偶数的数去除,剩余的数按原来从高位到低位的顺序组成一个新的数, 并通过形参指针n传回所指变量。 例如,输入一个数:27638496,新的数:为739。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include void fun(unsigned long *n) { unsigned long x=0, i; int t; i=1; while(*n) /**********found**********/ { t=*n % __1__; /**********found**********/ if(t%2!= __2__) { x=x+t*i; i=i*10; } *n =*n /10; } /**********found**********/ *n=__3__; } 29 main() { unsigned long n=-1; while(n>99999999||n<0) { printf("Please input(0 fun(int x) { int n, s1, s2, s3, t; /**********found**********/ n=__1__; t=100; /**********found**********/ while(t<=__2__) { s1=t%10; s2=(t/10)%10; s3=t/100; if(s1+s2+s3==15) { printf("%d ",t); n++; } /**********found**********/ __3__; } return n; } main() { int x=-1; while(x>999||x<0) { printf("Please input(0 #define N 3 int fun(int (*a)[N]) { int i,j,m1,m2,row,colum; m1=m2=0; for(i=0; i #define M 3 #define N 5 void fun(int (*a)[N],int k) { int i,j,p,temp; /**********found**********/ for(p=1; p<= __1__; p++) for(i=0; i #define N 20 void fun( int *a) { int i, x, n=0; x=rand()%20; /**********found**********/ 32 while (n<__1__) { for(i=0; i #include #define N 6 typedef struct node { int data; struct node *next; } NODE; void fun(NODE *h) { NODE *p, *q; int t; p = h; while (p) { /**********found**********/ q = __1__ ; /**********found**********/ while (__2__) { if (p->data > q->data) { t = p->data; p->data = q->data; q->data = t; } q = q->next; } /**********found**********/ 33 p = __3__ ; } } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h=NULL; for(i=0; idata=a[i]; q->next = NULL; if (h == NULL) h = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p=h; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() { NODE *head; int a[N]= {0, 10, 4, 2, 8, 6 }; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); fun(head); printf("\nThe list after inverting :\n"); outlist(head); } 43、给定程序中,函数fun的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从 头至尾结点数据域依次为:10、8、6、4、2。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include 34 #define N 5 typedef struct node { int data; struct node *next; } NODE; void fun(NODE *h) { NODE *p, *q, *r; /**********found**********/ p = h->__1__; /**********found**********/ if (p==__2__) return; q = p->next; p->next = NULL; while (q) { r = q->next; q->next = p; /**********found**********/ p = q; q = __3__; } h->next = p; } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h = (NODE *)malloc(sizeof(NODE)); h->next = NULL; for(i=0; idata=a[i]; q->next = NULL; if (h->next == NULL) h->next = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p = h->next; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } 35 main() { NODE *head; int a[N]={2,4,6,8,10}; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); fun(head); printf("\nThe list after inverting :\n"); outlist(head); } 44、给定程序中,函数fun的功能是:将形参n中,各位上为偶数的数取出,并按原来从高位到低位相反的顺序组成一个新的数,并作为 函数值返回。 例如,输入一个整数:27638496,函数返回值为:64862。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include unsigned long fun(unsigned long n) { unsigned long x=0; int t; while(n) { t=n%10; /**********found**********/ if(t%2==__1__) /**********found**********/ x=__2__+t; /**********found**********/ n=__3__; } return x; } main() { unsigned long n=-1; while(n>99999999||n<0) { printf("Please input(0 36 #include #define N 5 #define M 15 void fun(char (*ss)[M], char *substr) { int i,find=0; /**********found**********/ for(i=0; i< __1__ ; i++) /**********found**********/ if( strstr(ss[i], __2__) != NULL ) { find=1; puts(ss[i]); printf("\n"); } /**********found**********/ if (find==__3__) printf("\nDon't found!\n"); } main() { char x[N][M]={"BASIC","C langwage","Java","QBASIC","Access"},str[M]; int i; printf("\nThe original string\n\n"); for(i=0;i unsigned long fun(unsigned long n) { unsigned long x=0, s, i; int t; s=n; /**********found**********/ i=__1__; /**********found**********/ while(__2__) { t=s%10; if(t%2==0){ /**********found**********/ x=x+t*i; i=__3__; } s=s/10; } return x; } 37 main() { unsigned long n=-1; while(n>99999999||n<0) { printf("Please input(0 #define N 5 typedef struct student { long sno; char name[10]; float score[3]; } STU; void fun(char *filename) { FILE *fp; int i, j; STU s[N], t; /**********found**********/ fp = fopen(filename, __1__); fread(s, sizeof(STU), N, fp); fclose(fp); for (i=0; i #include #include void fun(char *s) { int k[26]={0},n,i,max=0; char ch; while(*s) { if( isalpha(*s) ) { /**********found**********/ ch=tolower(__1__); n=ch-'a'; /**********found**********/ k[n]+= __2__ ; } s++; /**********found**********/ if(max int fun(char *s, char *t) { int n=0; while(*s) { if(*s < 97) { /**********found**********/ *(t+n)= __1__ ; n++; } /**********found**********/ __2__ ; } *(t+n)=0; /**********found**********/ return __3__ ; } main() { char s[81],t[81]; int n; printf("\nEnter a string:\n"); gets(s); n=fun(s,t); printf("\nThere are %d letter which ASCII code is less than 97: %s\n",n,t); } 50、给定程序中,函数fun的功能是将不带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后, 从头至尾结点数据域依次为:10、8、6、4、2。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构~ #include #include #define N 5 typedef struct node { int data; struct node *next; 40 } NODE; /**********found**********/ __1__ * fun(NODE *h) { NODE *p, *q, *r; p = h; if (p == NULL) return NULL; q = p->next; p->next = NULL; while (q) { /**********found**********/ r = q->__2__; q->next = p; p = q; /**********found**********/ q = __3__ ; } return p; } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h=NULL; for(i=0; idata=a[i]; q->next = NULL; if (h == NULL) h = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p=h; if (p==NULL) printf("The list is NULL!\n"); else { printf("\nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End\n"); } } main() 41 { NODE *head; int a[N]={2,4,6,8,10}; head=creatlist(a); printf("\nThe original list:\n"); outlist(head); head=fun(head); printf("\nThe list after inverting :\n"); outlist(head); } 程序填空题参考答案: 1、x1=5.000000, x2=3.000000, x1*x1+x1*x2=40.000000 (1)double(2)f1(3)f2 2、存储了若干名学生的学号、姓名和3门课的成绩。按照姓名的字典序(从小到大)排序。 (1)struct student(2)n-1(3)a[i].name,a[j].name 3、例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000主函数中输出:46 32 40 45 48 (1)0(2)x[i]/N(3)j++ 4、给定程序中,函数fun的功能是:将a所指4×3矩阵中第k行的元素与第0行元素交换。 (1)k(2)N(3)a[k][i] 5、例如,主函数中输入字符串:32486和12345,在主函数中输出的函数值为:44831。 (1)'0'(2)s++(3)ctod(a)+ctod(b) 6、给定程序中,函数fun的功能是:计算下式前n项的和作为函数值返回。例如,当形参n的值为10时,函数返回:9.612558。 (1)0(2)n(3)(t*t) 7、给定程序中,函数fun的功能是:在3×4的矩阵中找出在行上最大、在列上最小的那个元素,若没有符合条件的元素则输出相应信息。 (1)j(2)0(3)i++ 8、在形参ss所指字符串数组中,删除所有串长超过k的字符串,函数返回所剩字符串的个数。ss所指字符串数组中共有N个字符串,且 串长小于M。 (1)N(2)k(3)ss[i] 9、例如:a所指变量中的学号、姓名、和三门课的成绩依次是:10001、"ZhangSan"、95、80、88,则修改后输出b中的数据应为:10002、 "LiSi"、95、80、88。 42 (1)a(2)b.name(3)score[i] 10、在形参ss所指字符串数组中,将所有串长超过k的字符串中右边的字符删除,只保留左边的k个字符。ss所指字符串数组中共有N个字符串,且串长小于M。 (1)[M](2)N(3)0 11、例如,形参s所指的字符串为:abcdefgh,n的值为5,程序执行后t所指字符数组中的字符串应为:defgh。 (1)t,s(2)s[i](3)0 12、例如,s所指字符串为:asd123fgh5##43df,处理后新字符串为:123543asdfgh##df。 (1)j(2)k(3)p 13、例如,当x值为5时,100,999之间各位上数字之和为5的整数有:104、113、122、131、140、203、212、221、230、302、311、320、401、410、500。共有15个。当x值为27时,各位数字之和为27的整数是:999。只有1个。 (1)999(2)t/10(3)x 14、例如,当x值为5时,100,999之间各位上数字之和为5的整数有:104、113、122、131、140、203、212、221、230、302、311、320、401、410、500。共有15个。当x值为27时,各位数字之和为27的整数是:999。只有1个。 (1)48(2)s++(3)sum 15、给定程序中,函数fun的功能是将带头节点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。 (1)h->next(2)p->next(3)>= 16、例如:a所指变量s中的学号、姓名、和三门课的成绩依次是:10001、" ZhangSan "、95、80、88,修改后输出t中的数据应为:10002、"LiSi "、96、81、89。 (1)struct student *(2)a->score[i](3)a 17、例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000 移动后的输出为:46 32 40 45 48 30 6 17 15 26 (1)s/N(2)j++(3)-1 18、例如,形参s所指的字符串为:This is a C language program.,函数的返回值为6。 (1)n++(2)0(3)s++ 19、在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返回该串在字符串数组中的位置(下标值),未找到则返回-1。ss所指字符串数组中共有N个内容不同的字符串,且串长小于M。 (1)N(2)i(3)-1 20、找出N×N矩阵中每列元素中的最大值,并按顺序依次存放于形参b所指的一维数组中。 (1)a[0][i](2)<(3)x,y 21、例如,LEVEL和Level是"回文",而LEVLEV不是"回文"。 (1)s(2)--(3)return 0 22、程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。所有学生数据均以二进制方式输出到student.dat文件中 (1)fp(2)==(3)fp 23、例如: b所指变量t中的学号、姓名、和三门课的成绩依次是: 10002、"ZhangQi"、93、85、87,修改后输出t中的数据应为:10004、" LiJie "、93、85、87。 (1)->sno(2)->name(3)&t 24、例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000移动后的输出为:30 6 17 15 26 46 32 40 45 48 (1)x[i]/N(2)j++(3)i++ 25、例如,若形参e的值为1e-3,函数的返回值2.735678。 (1)0(2)i++(3)2.*i 26、矩阵元素的构成规律是:最外层元素的值全部为1;从外向内第2层元素的值全部为2;第3层元素的值全部为3,…依次类推。例如,若N=5,生成的矩阵为: 1 1 1 1 1 1 2 2 2 1 1 2 3 2 1 43 1 2 2 2 1 1 1 1 1 1 (1)[N](2)i(3)i+1 27、函数fun的功能是用函数指针指向要调用的函数,并进行调用。规定在__2__处使f指向函数f1,在__3__处使f指向函数f2。当调用正确时,程序输出:x1=5.000000, x2=3.000000, x1*x1+x1*x2=40.000000 (1)double(2)f1(3)f2 28、函数fun的功能是将参数给定的字符串、整数、浮点数写到文本文件中,再用字符串方式从此文本文件中逐个读入,并调用库函数 atoi和atof将字符串转换成相应的整数、浮点数,然后将其显示在屏幕上 (1)FILE *(2)fclose(fp)(3)fp 29、计算下式前n项的和作为函数值返回。例如,当形参n的值为10时,函数返回:-0.204491。 (1)1(2)2*i(3)(-1) 30、存储了学生的学号、姓名和3门课的成绩。所有学生数据均以二进制方式输出到文件中。函数fun的功能是重写形参filename所指文件中最后一个学生的数据,即用新的学生数据覆盖该学生原来的数据,其它学生的数据不变。 (1)filename(2)fp(3)fp 31、例如,有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000主函数中输出:m=30.0 (1)*av(2)i(3)x[j] 32、函数fun的功能是将形参给定的字符串、整数、浮点数写到文本文件中,再用字符方式从此文本文件中逐个读入并显示在终端屏幕上。 (1)FILE *(2)fp(3)ch 33、例如:传给形参a的数据中,学号、姓名、和三门课的成绩依次是:10001、"ZhangSan"、95、80、88,修改后的数据应为:10002、"LiSi"、96、81、89。 (1)struct student(2)a.name(3)a.score[i] 34、利用指针数组对形参ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss所指字符串数组中共有N个字符串,且串长小于M (1)i(2)ps[i](3)tp 35、例如,s所指字符串为:asd123fgh543df,处理后新字符串为:asdfghdf12543。 (1)s[i](2)k(3)0 36、例如:若形参e的值为1e-3,函数的返回值为0.551690。 (1)3.(2)>(3)(2*i+1) 37、例如,输入一个数:27638496,新的数:为739。 (1)10(2)0(3)x 38、例如,当n值为500时,各位数字之和为15的整数有:159、168、177、186、195、249、258、267、276、285、294、339、348、357、366、375、384、393、429、438、447、456、465、474、483、492。共有26个。 (1)0(2)x(3)t++ 39、例如,以下3×3的矩阵就是一个"幻方": 4 9 2 3 5 7 8 1 6 (1)0(2)||(3)1 40、例如,有下列矩阵: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 若k为2,程序执行结果为 3 4 5 1 2 3 4 5 1 2 44 3 4 5 1 2 (1)k(2)N-1(3)temp 41、调用随机函数产生20个互不相同的整数放在形参a所指数组中(此数组在主函数中已置0)。 (1)N(2)break(3)n 42、即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。 (1)p->next(2)q(3)p->next 43、即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。 (1)next(2)0(3)r 44、例如,输入一个整数:27638496,函数返回值为:64862。 (1)0(2)10*x(3)n/10 45、ss所指字符串数组中共有N个字符串,且串长小于M。程序中库函数strstr(s1, s2)的功能是在s1串中查找s2子串,若没有,函数值为0,若有,为非0。 (1)N(2)substr(3)0 46、例如,从主函数输入一个整数:27638496,函数返回值为:26846。 (1)1(2)s(3)i*10 47、函数fun的功能是从形参filename所指的文件中读入学生数据,并按照学号从小到大排序后,再用二进制方式把排序后的学生数据输出到filename所指的文件中,覆盖原来的文件内容。 (1)"rb"(2)>(3)fwrite 48、例如,形参s所指的字符串为:abcAbsmaxless,程序执行后的输出结果为: letter 'a' : 3 times letter 's' : 3 times (1)*s(2)1(3)k[n] 49、例如,形参s所指的字符串为:Abc@1x56*,程序执行后t所指字符数组中的字符串应为:A@156*。 (1)*s(2)s++(3)n 50、即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。 (1)NODE(2)next(3)r 45
/
本文档为【C语言程序填空题】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索