C语言程序设计 (江宝钏 著) 清华大学出版社 第4章选择结构参考答案.doc

上传人:PIYPING 文档编号:10627756 上传时间:2021-05-27 格式:DOC 页数:8 大小:48.50KB
返回 下载 相关 举报
C语言程序设计 (江宝钏 著) 清华大学出版社 第4章选择结构参考答案.doc_第1页
第1页 / 共8页
C语言程序设计 (江宝钏 著) 清华大学出版社 第4章选择结构参考答案.doc_第2页
第2页 / 共8页
C语言程序设计 (江宝钏 著) 清华大学出版社 第4章选择结构参考答案.doc_第3页
第3页 / 共8页
C语言程序设计 (江宝钏 著) 清华大学出版社 第4章选择结构参考答案.doc_第4页
第4页 / 共8页
C语言程序设计 (江宝钏 著) 清华大学出版社 第4章选择结构参考答案.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《C语言程序设计 (江宝钏 著) 清华大学出版社 第4章选择结构参考答案.doc》由会员分享,可在线阅读,更多相关《C语言程序设计 (江宝钏 著) 清华大学出版社 第4章选择结构参考答案.doc(8页珍藏版)》请在三一文库上搜索。

1、一、写出表达式的值1. #include void main()int k = 12;float x = 9.5;double d = 2.7182;char zf = B;float w1, w2, w3, w4, w5, w6;w1=(int)x % k * d);w2=(x k + 5.6 & x d);w5=(zf = B);w6=(zf = B);printf(%f, %f, %f, %f, %f, %fn,w1, w2, w3, w4, w5, w6);运行结果:2. #include void main()int a = 5, b = 6, c = 7;int x, y, v1,

2、 v2, v3, v4, v5;v1 = a + b b) & !c |1;v4 = (x = a) | (y = b) & 0;v5 = !(a - b) - c & b + c/2;printf(%d, %d, %d, %d, %dn, v1, v2, v3, v4, v5);运行结果:二、程序阅读题1.#include void main()int x, y ;printf(please input x and y:n);scanf(x=%d,y=%d, &x, &y);if(x 10)if(y 10)printf(* n);elseprintf(# n);printf($ n);运行结

3、果:2. #include void main()int x, y ;printf(please input x and y:n);scanf(x=%d,y=%d, &x, &y);if(x 10)if(y 10)printf(* n);else printf(# n);printf($ n);运行结果:3#include void main()int a;scanf(%d, &a);if(a 50) printf(%d, a);if(a 40) printf(%d, a);if(a 30) printf(%d, a);运行结果:4. #include void main()int a = 1

4、, b = 2, c = 3, d = 0;if(a = 1 & b+ = 2)if(b != 2 | c- != 3)printf(%d, %d, %dn,a, b, c);else printf(%d, %d, %dn,a, b, c);else printf(%d, %d, %dn,a, b, c);运行结果:NOTICE:程序第四行的b+=2 应该改为b+=2。5. #include stdio.hvoid main()int m, n, x, y;scanf(%d,%d, &x, &y);m = 1; n = 1;if(x 0) m = m + 1;if(x y) n = m + n

5、;else if (x = y) n = 5;else n = 2 * m;printf(m = %d, n = %d, m, n);运行结果:6. #include stdio.hvoid main()int ch;ch = getchar();switch(ch - 1) case 0 :case 1 : putchar(ch + 3);case 2 : putchar(ch + 3); break;case 3 : putchar(ch + 3);default : putchar(ch + 1); break;printf(n);运行结果:7. #include void main()

6、int a = 1, b = 0;switch (a) case 1 :switch (b) case 0 : printf(*0*n); break;case 1 : printf(*1*n); break;case 2 : printf(*2*n); break;运行结果:三、编程题1.(1)#include void main()int x, y;printf(enter x and y :n);scanf(%d %d, &x, &y);if(y = 8)if(x = 5)printf( n);elseprintf($ $ $ $ $ n);printf(# # # # # n);pri

7、ntf(& & & & & n);运行结果:(2)#include void main()int x, y;printf(enter x and y :n);scanf(%d %d, &x, &y);if(y = 8)if(x = 5)printf( n);elseprintf(# # # # # n);printf($ $ $ $ $ n);printf(& & & & & n);运行结果:(3)#include void main()int x, y;printf(enter x and y :n);scanf(%d %d, &x, &y);if(y = 8)if(x = 5)printf

8、( n);elseprintf(# # # # # n);printf($ $ $ $ $ n);printf(& & & & & n);运行结果:(4)#include void main()int x, y;printf(enter x and y :n);scanf(%d %d, &x, &y);if(y = 8)if(x != 5)printf( n);elseprintf(# # # # # n);printf($ $ $ $ $ n);printf(& & & & & n);运行结果:2. #include void main()int x, y;printf(please inp

9、ut a data :n);scanf(%d, &x);if(x = 5)y = x * x + 3 * x - 4;elsey = x * x - 5 * x + 7;printf(y = %dn, y);3#include void main()char ch1, ch2, ch3;int d1;printf(please input 3 letters :n);scanf(%c %c %c, &ch1, &ch2, &ch3);ch1 = (ch1 = A & ch1 = A & ch2 = A & ch3 ch2)d1 = ch1; ch1 = ch2; ch2 = d1;if(ch1

10、 ch3)d1 = ch1; ch1 = ch3; ch3 = d1;if(ch2 ch3)d1 = ch2; ch2 = ch3; ch3 = d1;printf(%c %c %c n, ch1, ch2, ch3);4. #include void main()int h,pay;printf(enter working hours :n);scanf(%d, &h);if(h = 160)pay = 10 * h;elsepay = 10 * 160 + (h - 160) * 30;printf(pay = %dn, pay);5. #include void main()float

11、x, y, w, r=4.5;printf(enter x and y :n);scanf(%f %f, &x, &y);w = x * x + y * y;if(w = r*r)printf(the point is on the circle.n);else if(w r*r)printf(the point is outside the circle.n);elseprintf(the point is inside the circle.n);6. #include void main()int a, mb, pay, mi, cl, s;printf(please input dat

12、a :n);scanf(%d %d %d %d %d, &a, &mb, &pay, &mi, &cl);s = mb + pay - mi;if(s cl)printf(account is %d,credit limite is %d,new account is %dn, a, cl, s);printf(Credit limited exceed!n);elseprintf(credit is not limitedn);7. #include void main()int code, num;printf(enter a data :n);scanf(%d, &code);switc

13、h(code) case 801 : num = 53; break;case 802 : num = 60; break;case 803 : num = 55; break;case 804 : num = 56; break;case 805 : num = 60; break;case 806 : num = 58; break;case 807 : num = 57; break;case 808 : num = 59; break;printf(the number in the class is %dn, num);8#include void main()float score

14、;char grade;printf(enter a data :n);scanf(%f, &score);while(score 100 | score 0)printf(error! enter again:n);scanf(%f, &score);switch(int)(score/10) case 10 :case 9 : grade = A ; break;case 8 : grade = B ; break;case 7 : grade = C ; break;case 6 : grade = D ; break;case 5 :case 4 :case 3 :case 2 :case 1 :case 0 : grade = E ; break;printf(the score is %5.1f, the grade is %c.n, score, grade);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1