二级C语言上机题库及答案.doc

上传人:h**** 文档编号:138669 上传时间:2018-07-10 格式:DOC 页数:19 大小:310KB
下载 相关 举报
二级C语言上机题库及答案.doc_第1页
第1页 / 共19页
二级C语言上机题库及答案.doc_第2页
第2页 / 共19页
二级C语言上机题库及答案.doc_第3页
第3页 / 共19页
二级C语言上机题库及答案.doc_第4页
第4页 / 共19页
二级C语言上机题库及答案.doc_第5页
第5页 / 共19页
点击查看更多>>
资源描述

1、第一套题 上机填空: #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: %fn“,fun(e); 第一处答案: 3.0 第二处答案: 第三处答案:( 2*i+1) 或者 (t+1) 上机改错题: #i

2、nclude /*found*/ void fun ( int n ) int a, b, c, k; double s; s = 0.0; a = 2; b = 1; for ( k = 1; k double fun(int n) int i; double s, t; /*found*/ s=_1_; /*found*/ for(i=1; i0): “); scanf(“%d“, printf(“nThe result is: %fn“,fun(n); 第一处空答 案: 0 第一处空答案: n 第三处空答案:( t*t) 改错题 #include int fun (char *str,c

3、har *substr) int i,j,k,num=0; /*found*/ for(i = 0, stri, i+) for(j=i,k=0;substrk=strj;k+,j+) /*found*/ If(substrk+1=0) num+; break; return num; main() char str80,substr80; printf(“Input a string:“) ; gets(str); printf(“Input a substring:“) ; gets(substr); printf(“%dn“,fun(str,substr); 第一处错误: for(i =

4、 0, stri, i+) 改为 for(i = 0; stri;i+) 第二处错误: If(substrk+1=0) 改为 if(substrk+1=0) 即是将 ”If”改为 ”if” 第三套题 填空题 #include void fun(char *s, int *t) int i, n; n=0; /*found*/ for(i=0; _1_ !=0; i+) /*found*/ if(si=0 /*found*/ t = x ; x = y ; /*found*/ return(y) ; main() int a = 3, b = 8 ; printf(“%d %dn“, a, b)

5、 ; b = fun( printf(“%d %dn“, a, b) ; 第一处改错:将 t = x ; x = y ;改为 t=*x;*x=y; 第二处改错:将 return(y) 改为 return(t) 第四套题: 填空题 #include #define N 9 int fun(int a, int n) int i,j; j = 0; for (i=0; i int fun(int a,int b) int r,t; if(an)得余数 r,再用余数 r 去除原来的除数,得到新的余数,重复此过程直到余数为 0 时停止,此时的除数就是 m 和 n 的最大公约数。 第五套题: 填空题:

6、#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(n99999999|n void fun (long s, long *t) int d; long sl=1; /*found*/ t = 0; while ( s 0) d = s%10; /*found*/ if (d

7、%2 = 0) *t = d * sl + *t; sl *= 10; s /= 10; main() long s, t; printf(“nPlease enter s:“); scanf(“%ld“, fun(s, printf(“The result is: %ldn“, t); 第一处错误:将 t=0 改为 *t=0; 第二处错误:将 d%2 = 0 改为 d%2!=0 第六套题: # include #define N 9 void fun(int a, int n) int i,j, max, min, px, pn, t; for (i=0; i_3_) min = aj; p

8、n = j; if (pn != i) t = ai; ai = min; apn = t; if (px = i) px =pn; if (px != i+1) t = ai+1; ai+1 = max; apx = t; main() int bN=9,1,4,2,3,6,5,8,7, i; printf(“nThe original data :n“); for (i=0; i long fun(int g) /*found*/ switch(g); case 0: return 0; /*found*/ case 1 ;case 2 : return 1 ; return( fun(g

9、-1)+fun(g-2) ); main() long fib; int n; printf(“Input n: “); scanf(“%d“, printf(“n = %dn“,n); fib=fun(n); printf(“fib = %dnn“,fib); 第一处错误:将 switch(g); 改为 switch(g) ,即是去掉“;” 第二处错误:将 case 1 ;case 2 : return 1 ;改为 case 1 : case 2 : return 1 ;即是将 case1 后“;” 改为“:” 第七套题: 填空题 #include /*found*/ _1_ fun(cha

10、r ch) /*found*/ if (ch=0 return ch ; main() char c1, c2; printf(“nThe result :n“); c1=2; c2 = fun(c1); printf(“c1=%c c2=%cn“, c1, c2); c1=8; c2 = fun(c1); printf(“c1=%c c2=%cn“, c1, c2); c1=a; c2 = fun(c1); printf(“c1=%c c2=%cn“, c1, c2); 第一空: char 第二空: ch=9 第三空: 0 改错题: #include void fun(char *p, char *b) int i, k=0; while(*p) i=1; while( i=3 k+; p+; i+;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 参考答案

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。