计算机二级考试(C语言)复习资料题目答案

  • 格式:doc
  • 大小:158.00 KB
  • 文档页数:23

上海理工大学 上海市计算机二级考试(C语言)复习资料题目解答

第一部份:基础知识 1. B 2. C 3. C 4. B 5. D 6. A 7. A 8. C 9. C 10. A 11. C 12. A 13. B 14. B 15. C 16. B 17. D 18.B 19. A 20. C 21. C 22. B 23. B 24. C 25. D 26. B 27. B 28. D 29. C 30. C 31. D 32. C 33. C 34. B 35. C 36. D 37. C 38. B 39. C 40. B 41. C 42. B 43. C 44. B 45. B 46. A 47. D 48. D 49. D 50. D 51. A 52. C 53. (Sqrt( x)+ sqrt( y))/2/( x+ y) or similar 54. The "234" is namely the string234 55. B 56.D 57.D 58. B 59. C 60.D 61.B 62. D 63.A 64.D 65.C 66.B 67.C 68. D 69. C 70.C 71.A 72.A 73.B 74.B 75.C 76. C 77.C 78.A 79.D 80.B 81.D 82.D 83.C 84.D 85.B 86.D 87.B 88.D 89.B 90.C 91.C 92.B 93.B 94.B 95. N+'0' 96. 0The x1400 moves is ex-, binary system 00010100 Bs or eight enter the 024 Qs

of system 97. The first answer 65 ds or 41 hses or a the second answer 1 or not0 98. 85 99. 14 100. x=-60

第二部分 读程序,写结果 1. 0,2,4,3 2. 3.142 3. 8 4. m/10%10*100+m/100*10+m%10 5. ?uoy_era_woHHwaeyu 6. 7,3 7. 54656 8. A the = biggest number, b= is most the fraction 9. 1 10. 5,5 11. 9876543210 12. 1 3 5 7 9 13. j=0 m=4 The first k : 4 j=1 m=4 14. The second k : 5 15. Count=0, position=0( did not find out) 16. 0 -30 17. 输出12 14 22 24 32 34,函数s是用插入法对数组a的前n个元素从小到大排序 18. 输出 2 3 5 7 11 13 函数p的功能是求k(包括k )以内的质数 19. 输出 n=91, a[]=0, 10, 21, 31 20. 输出 Feith 21. 输出 72 56 38 49 22. 81818181 23. k=5 24. 1 25. 9 26. 用递归函数实现10->2进制转换

第三部分 程序改错 1. #4 scanf(“%d”,&x); #10 low=m+1 #11 high=m-1 2. #7 scanf(“%c”,&str[i]); #8 break 3. #7 x , n #13 n==0 #15 x*xn(x,n-1) 4. #5 t=t*x/i #15 e=ex(x) 5. #4 scanf(%d”,&x); #10 low=m+1 #11 high=m-1 6. #3 fun(str[]) #5 while (*(str+num)!=’\0’) num++; #9 char str[10],*p=str; 7. #14 flag=0 ; #19 flag=1; i++; 8. #3 func(str[]) #5 while (*(str+num)!=’\0’) num++; #9 {char str[10],*p=str; 9. #5 n=n/10; #6 while (!n); #12 scanf(“%ld”,&n); 10. #10 else if (x>a[m]) low=m+1; #11 else high=m-1; 11. #6 a=1.0; #8 a/=i; #9 e+=a; 12. #6 char *temp; #10 if(strcmp(temp,name[i])>0) #12 printf(“%s \n”, temp ); 13. #3 str[i]!=’\0’ #4 str[i]>= ’0’ && str[i]<=’9’ #10 data = data*16 + n; 14. #3 int n1=0,n2=0, i; #6 if (str[i]==’#’) #8 if (str[i]>=’0’&&str[i]<=’9’) #9 n2++; } 15. #5 i #7 sum=max=min=a[0] #12 aver=(float)(sum-max-min)/(N-2) 16. #7 scanf(“%c”,&str[i]); #8 break 17. #7 x , n #13 n==0 #15 x*xn(x,n-1) 18. #4 double fun(double eps) #8 while (t>=eps) #13 return (2*s); 19. #3 long fun(char *p) #17 num+=p[i]-48;或 num+=p[i]-‘0’; #29 printf(“%ld\n”,n); /* 必须有%ld */ 20. #9 a[j]#15 b[k]>a[j]&&a[j] #18 a[j]=b[k] 21. #2 void printcol(int (*p)[N], int row, int col) #6 printf(“\t\t%d\n”,*(*(p+i)+col)); #14 } while (col<0||col>N-1); 22. #2 …(char *s) #4 (*p) 或…(*p!=0) 或…(*p!='\0’) #9 gets(x); 23. #6 t=n%10; #10 n/=10; #11 } while(n); 或 } while (n!=0); 24. #4 { for (j=0;j<=20-i;j++) #5 printf(" "); #8 printf("\n"); 25. #2 char *fun(char *s,char *t) #4 a=0;(或a=NULL;) #8 if (*r ==*p) {r++; p++;}

第四部分 编程序 1. 设有链表结点的结构及变量如下:) struct st { int num ; struct st *next; }; struct st *head, *p1 ,* p2; 编写函数create(),是个无参数函数,创建链表,num=0结束,返回指针值,指向首结点head。 #define NULL 0 #define LEN sizeof(struct st) struct st { int num; struct st *next; }; int n=0; struct st *creat() { struct st *head, *p1,*p2; p1=p2=(struct st *)malloc(LEN); scanf("%u,%d",&p1->num,&p1->score); head=NULL; while (p1->num!=0) { n=n+1; if (n==1) head=p1; else p2->next=p1; p2=p1; p1=(struct st *)malloc(LEN); scanf("%u,%d",&p1->num,&p1->score); } p2->next=NULL; return (head); } 2. 对N个数据,降序排列并输出 #define N 10 main() { int a[N]={1,5,0,3,-6,9,-8,7,2,4}; int i,j,t; for (i=0;i for (j=i;j if (a[i] { t=a[i]; a[i]=a[j];a[j]=t;} for (i=0;i printf("%3d",a[i]); }

3. 有二维数组如下 1 2 3 4 5 6 7 8 9 10 11 12 现要求输入某元素所在的行和列,将其后的所有元素输出,必须用指针技术编程。 例如,输入2 ,3 表示从第二行第三列元素7开始输出其余元素 7 8 9 10 11 12 main() { int a[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