为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

计算机二级C

2010-11-02 27页 doc 591KB 36阅读

用户头像

is_263408

暂无简介

举报
计算机二级C2.1填空题: #include int c1,c2,c3; void fun(long n) { c1 = c2 = c3 = 0; while (n) { /**********found**********/ switch(n%10) { /**********found**********/ case 1: c1++; break; /**********found**********/ case 2: c2++ ; break; 4.1填空题: #include #include double fun(doub...
计算机二级C
2.1填空: #include int c1,c2,c3; void fun(long n) { c1 = c2 = c3 = 0; while (n) { /**********found**********/ switch(n%10) { /**********found**********/ case 1: c1++; break; /**********found**********/ case 2: c2++ ; break; 4.1填空题: #include #include double fun(double x) { double f, t; int n; f = 1.0 + x; /**********found**********/ t = x; n = 1; do { n++; /**********found**********/ t *= (-1.0)*x/ n; f += t; } /**********found**********/ while ( fabs(t)>= 1e-6); 4.2改错题: 给定程序modi.c中函数fun的功能是: 求整数x的y次方的低3位值。例如,整数5的6次方为15625,此值的低3位值为625。 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! #include long fun(int x,int y,long *p ) { int i; long t=1; /**************found**************/ for(i=1; i typedef struct { int num; char name[9]; char sex; struct { int year,month,day ;} birthday; float score[3]; }STU; /**********found**********/ void show(STU tt) tt { int i; printf("\n%d %s %c %d-%d-%d", tt.num, tt.name, tt.sex, tt.birthday.year, tt.birthday.month, tt.birthday.day); for(i=0; i<3; i++) /**********found**********/ printf("%5.1f", tt.score[i]); tt.score[i] printf("\n"); } main( ) { STU std={ 1,"Zhanghua",'M',1961,10,8,76.5,78.0,82.0 }; printf("\nA student data:\n"); /**********found**********/ show(std); std } 11.1填空题: 人员由编号和出生年、月、日组成,N名人员的数据已在主函数中存入结构体数组std中,且编号唯一。函数fun的功能是:找出指定编号人员的数据,作为函数值返回,由主函数输出,若指定编号不存在,返回数据中编号为空串。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK01.C中。 不得增行或删行,也不得更改程序的结构! #include #include #define N 8 typedef struct { char num[10]; int year,month,day ; }STU; /**********found**********/ ___1___ fun(STU *std, char *num) STU { int i; STU a={"",9999,99,99}; for (i=0; i typedef struct { int num; char name[9]; float score[3]; }STU; void show(STU tt) { int i; printf("%d %s : ",tt.num,tt.name); for(i=0; i<3; i++) printf("%5.1f",tt.score[i]); printf("\n"); } /**********found**********/ void modify(STU *ss,float a) STU { int i; for(i=0; i<3; i++) /**********found**********/ ss-> score[i] *=a; score[i] } main( ) { STU std={ 1,"Zhanghua",76.5,78.0,82.0 }; float a; printf("\nThe original number and name and scores :\n"); show(std); printf("\nInput a number : "); scanf("%f",&a); /**********found**********/ modify(&std,a); &std printf("\nA result of modifying :\n"); show(std); 14.1填空题: 给定程序中,函数fun的功能是:将形参指针所指结构体数组中的三个元素按num成员进行升序排列。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include typedef struct { int num; char name[10]; }PERSON; /**********found**********/ void fun(PERSON *std ) *std { /**********found**********/ PERSON temp; PERSON if(std[0].num>std[1].num) { temp=std[0]; std[0]=std[1]; std[1]=temp; } if(std[0].num>std[2].num) { temp=std[0]; std[0]=std[2]; std[2]=temp; } if(std[1].num>std[2].num) { temp=std[1]; std[1]=std[2]; std[2]=temp; } } main() { PERSON std[ ]={ 5,"Zhanghu",2,"WangLi",6,"LinMin" }; int i; /**********found**********/ fun(std); std printf("\nThe result is :\n"); for(i=0; i<3; i++) printf("%d,%s\n",std[i].num,std[i].name); } 16.1填空题: #include #include #define M 5 #define N 20 void fun(char (*ss)[N]) { int i, j, k, n[M]; char t[N]; for(i=0; in[j]) k=j; k=j if(k!=i) { strcpy(t,ss[i]); strcpy(ss[i],ss[k]); /**********found**********/ strcpy(ss[k], t); t n[k]=n[i]; #include double fun(double e) { int i, k; double s, t, x; s=0; k=1; i=2; /**********found**********/ x=__1__/4; 3.0 /**********found**********/ while(x > e) { s=s+k*x; k=k* (-1); t=2*i; /**********found**********/ x=__3__/(t*t); t+1 i++; } return s; } main() { double e=1e-3; printf("\nThe result is: %f\n",fun(e)); } 填空题: 程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。函数fun的功能是将形参a所指结构体变量s中的数据进行修改,并把a中地址作为函数值返回主函数,在主函数中输出修改后的数据。 例如:a所指变量s中的学号、姓名和3门课的成绩依次是: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) struct student * { int i; a->sno = 10002; strcpy(a->name, "LiSi"); /**********found**********/ for (i=0; i<3; i++) __2__ += 1; a->score[i] /**********found**********/ return __3__ ; a } 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]); 7.2改错题: 下列给定MODI1.C程序中的函数Creatlink的功能是:创建带头结点的单向链,并为各结点数据域赋0到m-1的值。 请改正函数Creatlink中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! #include #include typedef struct aa { int data; struct aa *next; } NODE; NODE *Creatlink(int n, int m) { NODE *h=NULL, *p, *s; int i; /**********found***********/ p=(NODE )malloc(sizeof(NODE)); p=(NODE *)malloc(sizeof(NODE)); h=p; p->next=NULL; 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; } /**********found***********/ return p; return h; } outlink(NODE *h) { NODE *p; p=h->next; printf("\n\nTHE LIST :\n\n HEAD "); while(p) { printf("->%d ",p->data); p=p->next; } 9.1填空题: 给定程序中,函数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__ ; h while (p) { /**********found**********/ q = __2__ ; p->next 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; } } 10.1填空题: 给定程序中,函数fun的功能是将参数给定的字符串、整数、浮点数写到文本文件中,再用字符方式从此文本文件中逐个读入,并显示在终端屏幕上。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include void fun(char *s, int a, double f) { /**********found**********/ __1__ fp; FILE * 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__)) { fp /**********found**********/ putchar(__3__); ch = fgetc(fp); } ch putchar('\n'); fclose(fp); } main() { char a[10]="Hello!"; int b=12345; double c= 98.76; fun(a,b,c); } *10.2改错题: 给定程序modi.c中,函数fun的功能是:依次取出字符串中所有数字字符,形成新的字符串,并取代原字符串。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! #include void fun(char *s) { int i,j; for(i=0,j=0; s[i]!='\0'; i++) if(s[i]>='0' && s[i]<='9') /**********found**********/ s[j]=s[i]; s[j++]=s[i]; /**********found**********/ s[j]="\0"; s[j]=’\0’; } main() { char item[80]; printf("\nEnter a string : ");gets(item); printf("\n\nThe string is : \"%s\"\n",item); fun(item); printf("\n\nThe string of changing is : \"%s\"\n",item ); } *19.1填空题: 给定程序中,函数fun的功能是;将a所指3×5矩阵中第k列的元素左移到第0列,第k列以后的每列元素依次左移,原来左边的各列依次绕到右边。 例如:有下列矩阵: 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 3 4 5 1 2 请在程序的下划线处填入正确的内容并把下划线删除,便程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中,不得增或删行,也不得更改程序的结构! #include #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++) k for(i=0; i #define M 10 int a[M][M] = {0} ; /**************found**************// fun(int **a, int m) fun(int a[][M], int m) { int j, k ; for (j = 0 ; j < m ; j++ ) for (k = 0 ; k < m ; k++ ) /**************found**************/ a[j][k] = k * j ; a[j][k] =( k +1)* (j+1 ); } *20.2改错题: 给定程序MODI1.C中函数fun的功能是:根据整型形参m,计算如下的值。 例如:若主函数中输入5,则输出-0.283333。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! #include double fun( int m ) { double t = 1.0; int i; for( i = 2; i <= m; i++ ) /**********found**********/ t = 1.0-1 /i; t = t-1.0 /i; /**********found**********/ _______; return t; 21.1填空题: 给定程序中,函数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__) [N] { int i,j,k,m; if(N%2==0) m=N/2 ; else m=N/2+1; for(i=0; i #define M 3 #define N 4 void fun(int (*a)[N]) { int i=0,j,find=0,rmax,c,k; while( (i int fun(char *s, char *t) { int n=0; while(*s) { if(*s < 97) { /**********found**********/ *(t+n)= __1__ ; n++; } *s /**********found**********/ __2__ ; s++ } *(t+n)=0; /**********found**********/ return __3__ ; n } /**********found**********/ x=__1__/4; 3.0 /**********found**********/ while(x __2__ e) > { s=s+k*x; k=k* (-1); t=2*i; /**********found**********/ x=__3__/(t*t); (2*i+1) i++; } return s; *28.1填空题: 给定程序中,函数fun的功能是:找出形参s 所指字符串中出现频率最高的字母(不区分大小写),并统计出其出现的次数。 例如:形参s所指的字符串为:abcAbsmaxless,程序执行后的输出结果为: letter ‘a’ : 3 times letter ‘s’ : 3 times 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得删行或增行,也不得更改程序的结构! #include #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__); *s n=ch-'a'; /**********found**********/ k[n]+= __2__ ; 1 } s++; /**********found**********/ if(max #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__); t,s else { /**********found**********/ for(i=len-n; i<=len-1; i++) t[j++]= __2__ ; s[i] /**********found**********/ t[j]= __3__ ; ‘\0’ *34.1填空题: 给定程序中,函数fun的功能是:计算x所指数组中N个数的平均值(规定所有数均为正数),平均值通过形参返回主函数,将小于平均值且最接近平均值的数作为值返回,在主函数中输出。 例如:有10个正数:46 30 32 40 6 17 45 15 48 26,平均值为:30.500000 主函数输出:m=30.0 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include #define N 10 double fun(double x[],double *av) { int i,j; double d,s; s=0; for(i=0; i #include #include int fun(char *s) { int sum=0; while(*s) { /**********found**********/ if( isdigit(*s) ) sum+= *s- __1__ ; ‘0’ /**********found**********/ __2__; s++ } /**********found**********/ return __3__ ; sum } 36.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) double { if (i==1) /**********found**********/ return __2__(x); f1 else /**********found**********/ return __3__(x, y); f2 } 37.1填空题: 给定程序中,函数fun的功能是:将形参s所指字符串中的所有字母字符顺序前移,其它字符顺序后移,处理后新字符串的首地址作为函数值返回。 例如:s所指字符串为:asd123fgh543df ,处理后新字符串为:asdfghdf12543。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #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='a')&&(s[i]<='z'))||((s[i]>='A')&&(s[i]<='Z'))) { /**********found**********/ t[j]=__1__; j++;} s[i] else { p[k]=s[i]; k++; } } /**********found**********/ for(i=0; i<__2__; i++) t[j+i]=p[i]; k /**********found**********/ t[j+k]= __3__; ‘\0’ return t; *38.1填空题: 给定程序中,函数fun的功能是:判断形参s所指字符串是否是“回文”(Palindrome),若是,函数返回值为1;不是,函数返回值为0;“回文”是正读和反读都一样的字符串(不区分大小写字母)。 例如:LEVEL和level是“回文”,而LEVLEV不是“回文”。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include #include #include int fun(char *s) { char *lp,*rp; /**********found**********/ lp= __1__ ; s rp=s+strlen(s)-1; while((toupper(*lp)==toupper(*rp)) && (lp #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;} j++ for(i=0; i #define N 20 void fun( int *a) { int i, x, n=0; x=rand()%20; /**********found**********/ while (n<__1__) N { for(i=0; i void fun(unsigned long *n) { unsigned long x=0, i; int t; i=1; while(*n) /**********found**********/ { t=*n % __1__; 10 /**********found**********/ if(t%2!= __2__) 0 { x=x+t*i; i=i*10; } *n =*n /10; } /**********found**********/ *n=__3__; x } *43.1填空题: 给定程序中,函数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__) 0 /**********found**********/ x=__2__+t; x*10 /**********found**********/ n=__3__; n/10 } return x; 44.1填空题: 给定程序中,函数fun的功能是:将a和b所指的两个字符串转换成面值相同的整数,并进行相加作为函数值返回,规定字符串中只包含9个以下数字字符。 例如:主函数中输入字符串:32486和12345,在主函数中输出的函数值为:44831。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include #include #include #define N 9 long ctod( char *s ) { long d=0; while(*s) if(isdigit( *s)) { /**********found**********/ d=d*10+*s-__1__; ‘0’ /**********found**********/ __2__; } s++ return d; } 45.1填空题: 给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中小于平均值的数据移至数组的前部,大于等于平均值的数据移至数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。 例如:有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 #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 #include #define N 5 #define M 8 int fun(char (*ss)[M],char *t) { int i; /**********found**********/ for(i=0; i< __1__ ; i++) N /**********found**********/ if(strcmp(ss[i],t)==0 ) return __2__ ; i 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 #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++) N /**********found**********/ if( strstr(ss[i], __2__) != NULL ) substr { find=1; puts(ss[i]); printf("\n"); } /**********found**********/ if (find==__3__) printf("\nDon't found!\n"); 0 } 49.1填空题: 给定程序中,函数fun的功能是:在形参ss所指字符串数组中,删除所有串长超过k的字符串,函数返回所剩字符串的个数。ss所指字符串数组中共有N个字符串,且串长小于M。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序
/
本文档为【计算机二级C】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索