您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > C/C++资料 > 上海市计算机二级考试(C语言)复习资料题目答案
中慧教育伴您考试顺利!上海理工大学上海市计算机二级考试(C语言)复习资料题目解答第一部份:基础知识1.B2.C3.C4.B5.D6.A7.A8.C9.C10.A11.C12.A13.B14.B15.C16.B17.D18.B19.A20.C21.C22.B23.B24.C25.D26.B27.B28.D29.C30.C31.D32.C33.C34.B35.C36.D37.C38.B39.C40.B41.C42.B43.C44.B45.B46.A47.D48.D49.D50.D51.A52.C53.(Sqrt(x)+sqrt(y))/2/(x+y)orsimilar54.The234isnamelythestring23455.B56.D57.D58.B59.C60.D61.B62.D63.A64.D65.C66.B67.C68.D69.C70.C71.A72.A73.B74.B75.C76.C77.C78.A79.D80.B81.D82.D83.C84.D85.B86.D87.B88.D89.B90.C91.C92.B93.B94.B95.N+'0'96.0Thex1400movesisex-,binarysystem00010100Bsoreightenterthe024Qsofsystem97.Thefirstanswer65dsor41hsesorathesecondanswer1ornot098.8599.14100.x=-60第二部分读程序,写结果1.0,2,4,32.3.1423.84.m/10%10*100+m/100*10+m%105.?uoy_era_woHHwaeyu6.7,37.546568.Athe=biggestnumber,b=ismostthefraction9.110.5,511.987654321012.1357913.j=0m=4Thefirstk:4j=1m=414.Thesecondk:515.Count=0,position=0(didnotfindout)16.0中慧教育伴您考试顺利!-3017.输出121422243234,函数s是用插入法对数组a的前n个元素从小到大排序18.输出23571113函数p的功能是求k(包括k)以内的质数19.输出n=91,a[]=0,10,21,3120.输出Feith21.输出7256384922.8181818123.k=524.125.926.用递归函数实现10-2进制转换第三部分程序改错1.#4scanf(“%d”,&x);#10low=m+1#11high=m-12.#7scanf(“%c”,&str[i]);#8break3.#7x,n#13n==0#15x*xn(x,n-1)4.#5t=t*x/i#15e=ex(x)5.#4scanf(%d”,&x);#10low=m+1#11high=m-16.#3fun(str[])#5while(*(str+num)!=’\0’)num++;#9charstr[10],*p=str;7.#14flag=0;#19flag=1;i++;8.#3func(str[])#5while(*(str+num)!=’\0’)num++;#9{charstr[10],*p=str;9.#5n=n/10;#6while(!n);#12scanf(“%ld”,&n);10.#10elseif(xa[m])low=m+1;#11elsehigh=m-1;11.#6a=1.0;#8a/=i;#9e+=a;12.#6char*temp;#10if(strcmp(temp,name[i])0)#12printf(“%s\n”,temp);13.#3str[i]!=’\0’#4str[i]=’0’&&str[i]=’9’#10data=data*16+n;中慧教育伴您考试顺利!14.#3intn1=0,n2=0,i;#6if(str[i]==’#’)#8if(str[i]=’0’&&str[i]=’9’)#9n2++;}15.#5iN#7sum=max=min=a[0]#12aver=(float)(sum-max-min)/(N-2)16.#7scanf(“%c”,&str[i]);#8break17.#7x,n#13n==0#15x*xn(x,n-1)18.#4doublefun(doubleeps)#8while(t=eps)#13return(2*s);19.#3longfun(char*p)#17num+=p[i]-48;或num+=p[i]-‘0’;#29printf(“%ld\n”,n);/*必须有%ld*/20.#9a[j]a[i]#15b[k]a[j]&&a[j]#18a[j]=b[k]21.#2voidprintcol(int(*p)[N],introw,intcol)#6printf(“\t\t%d\n”,*(*(p+i)+col));#14}while(col0||colN-1);22.#2…(char*s)#4(*p)或…(*p!=0)或…(*p!='\0’)#9gets(x);23.#6t=n%10;#10n/=10;#11}while(n);或}while(n!=0);24.#4{for(j=0;j=20-i;j++)#5printf();#8printf(\n);25.#2char*fun(char*s,char*t)#4a=0;(或a=NULL;)#8if(*r==*p){r++;p++;}第四部分编程序1.设有链表结点的结构及变量如下:)structst{intnum;structst*next;};structst*head,*p1,*p2;编写函数create(),是个无参数函数,创建链表,num=0结束,返回指针值,指向首结点head。#defineNULL0#defineLENsizeof(structst)structst{intnum;structst*next;中慧教育伴您考试顺利!};intn=0;structst*creat(){structst*head,*p1,*p2;p1=p2=(structst*)malloc(LEN);scanf(%u,%d,&p1-num,&p1-score);head=NULL;while(p1-num!=0){n=n+1;if(n==1)head=p1;elsep2-next=p1;p2=p1;p1=(structst*)malloc(LEN);scanf(%u,%d,&p1-num,&p1-score);}p2-next=NULL;return(head);}2.对N个数据,降序排列并输出#defineN10main(){inta[N]={1,5,0,3,-6,9,-8,7,2,4};inti,j,t;for(i=0;iN-1;i++)for(j=i;jN;j++)if(a[i]a[j]){t=a[i];a[i]=a[j];a[j]=t;}for(i=0;iN;i++)printf(%3d,a[i]);}3.有二维数组如下123456789101112现要求输入某元素所在的行和列,将其后的所有元素输出,必须用指针技术编程。例如,输入2,3表示从第二行第三列元素7开始输出其余元素789101112main(){inta[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};int*p,i,j;scanf(%d%d,&i,&j);p=&a[i-1][j-1];for(;p&a[0][0]+12;p++)printf(%5d,*p);}4.将一个磁盘文件的数据读到一个链表中去,队列或堆栈不论。要求如下:磁盘文件放在A盘的一级目录(即一级子文件夹)abc下,文件名是flile.dat链表结点的结构为中慧教育伴您考试顺利!structnode{charval;strctnode*next;}工作用的指针名为h和p#includestdio.h#includestring.hstructnode{charval;structnode*next;};structnode*create(FILE*fp){structnode*p,*h;chard;h=NULL;fp=fopen(a:\\abc\\file.dat,r);while(!feof(fp)){fread(&d,2,1,fp);p=(structnode*)malloc(sizeof(structnode));p-val=d;p-next=h;h=p;}fclose(fp);printf(\n);printlk(h);returnh;}printlk(structnode*h){structnode*p;printf(printlink...\n);p=h;while(p){printf(%c,p-val);p=p-next;}}main(){structnode*h,*p;FILE*fp;fp=fopen(rd_data,r);if(fp==NULL){printf(readdataerror!\n);exit(0);}h=create(fp);printlk(h);exit(0);}5.试写一个函数(函数名为f),以十进制正整数n为整型参数,函数的返回值是n的位数(例:278是三位数)。要求循环结构需用do_while控制结构。intf(longn)中慧教育伴您考试顺利!{intc=0;do{c++;n=n/10;}while(n);returnc;}main(){longn;intnum;scanf(%ld,&n);num=f(n);printf(%ldhas%dnumbers\n,n,num);}6.将一个n×n的矩阵行列转置后输出,转置功能由函数reverse实现,试编程。#defineN3voidreverse(floatx[][N],intn){inti,j;floatt;for(i=0;in;i++)for(j=i;jn;j++){t=x[i][j];x[i][j]=x[j][i];x[j][i]=t;}}voidprtable(floatx[][N],intn){inti,j;for(i=0;in;i++){for(j=0;jn;j++)printf(%10.4f,x[i][j]);printf(\n);}}main(){inti,j;floata[][N]={{1,2,3},{4,5,6},{7,8,9}};prtable(a,N);reverse(a,N);prtable(a,N);}7.试用do_while控制结构,计算下列级数的和s=1+3+5+...+(2i-1)+...当累加到某项s的值大于100时,该项及以后各项不再累加,结束循环求和。main(){ints,i;s=0;i=0;do{i++;中慧教育伴您考试顺利!s+=2*i-1;}while(s+(2*i+1)=100);printf(sum=%d,i=%d\n,s,i);}8.编程序用于将原字符串按某种规律变成密码:即将字母A变成E,B变成F,…;W变成A,X变成B,…,Z变成D,对小写字母也是如此编码,标点符号、空格维持原状。#defineN4#includestdio.hdecode(){charc;while((c=getchar())!='\n'){if((c='a'&&c='z')||(c='A'&&c='Z')){c=c+4;if(c'Z'&&c='Z'+N||c'z')c=c-26;}printf(%c,c);}}main(){decode();}9.编写一个带参数宏trans(F),输入一个华氏温度F,要求输出摄氏温度c。公式是cF)32(95,取2位小数。#definetrans(F)(F-32)*5/9.0main(){floatc,F;scanf(
本文标题:上海市计算机二级考试(C语言)复习资料题目答案
链接地址:https://www.777doc.com/doc-7252082 .html