《C语言程序设计》课件chapter3-answer.doc

上传人:eieieie 文档编号:21713195 上传时间:2023-11-03 格式:DOC 页数:4 大小:69KB
返回 下载 相关 举报
《C语言程序设计》课件chapter3-answer.doc_第1页
第1页 / 共4页
《C语言程序设计》课件chapter3-answer.doc_第2页
第2页 / 共4页
《C语言程序设计》课件chapter3-answer.doc_第3页
第3页 / 共4页
《C语言程序设计》课件chapter3-answer.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《《C语言程序设计》课件chapter3-answer.doc》由会员分享,可在线阅读,更多相关《《C语言程序设计》课件chapter3-answer.doc(4页珍藏版)》请在三一文库上搜索。

1、第三章 分支程序设计参考答案一、选择题(把正确选项的字母标号填到表格中)题号1234567891011121314151617181920答案CDCBBBCCAADCDDCABACC- 4 -二、判断题(错的填,对的填)题号1234567891011121314151617181920答案三、应用题1.程序改错题#include int main(void)float x, y1, y2;printf(Please enter x: );scanf(%f,&x);if(x 0) y1 = 5 / x; y2 = 8 / x; else if(x = 0) y1 = y2 = 0; else y

2、1 = 2 * x; y2 = 3 * x; printf(nx=%.2f,y1=.2f,y2=.2fn,x,y1,y2);return 0;2.读程题题号答案题号答案x的值y的值z的值x的值y的值z的值(1)412(6)-100(2)001(7)010(3)202(8)131(4)001(9)131(5)001(10)4303.改写程序题switch(ch) case E: case e:countE+; break; case A: case a:countA+; break; case I: case i:countI+; break;default: print (“Error-Not

3、 A, E, or I an”); 四、编程题1.#include #include int main(void)int a;int b;int c;float x1;float x2;float p;printf(请输入方程的三个系数: );scanf(%d%d%d,&a,&b,&c);if (a=0)if (b=0)printf(系数a和b均为0, 构不成方程!n);elsex1 = -c / (float)b;printf(方程只有一个根: x = %.1fn,x1);elsep = b * b - 4 * a * c;if (p 0)printf(方程没有实根!n);else if (

4、p=0)x1 = -b /(float)(2 * a);printf(方程有两个相等的实根: x1=x2=%.1fn,x1);elsex1 = (-b + sqrt(p)/(2 * a);x2 = (-b - sqrt(p)/(2 * a);printf(方程有两个不相等的实根: x1=%.1f,x2=%.1fn,x1,x2);return 0; 2.#include stdio.h#include math.hint main(void)int a,b,c;float s;float area;printf(Enter three integarl sides of a triangle:

5、);scanf(%d%d%d,&a,&b,&c);if(a=0|b=0|c=0|a+b=c|a+c=b|b+c=A&c=a&c=0&c=9)printf(%c is a numbern,c);else if(c=40)printf(%c is a spacen,c);elseprintf(%c is othern,c);return 0;(2)使用switch-case语句实现#include stdio.hint main(void)char c;printf(Press any key: );scanf(%c,&c);switch(c)case A:case B:case C:case D

6、:case E:case F:case G:case H:case I:case J:case K:case L:case M:case N:case O:case P:case Q:case R:case S:case T:case U:case V:case W:case X:case Y:case Z:case a:case b:case c:case d:case e:case f:case g:case h:case i:case j:case k:case l:case m:case n:case o:case p:case q:case r:case s:case t:case u:case v:case w:case z:case y:case z:printf(%c is a lettern,c);break;case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:printf(%c is a numbern,c);break;case 40:printf(%c is a spacen,c);break;default:printf(%c is othern,c);return 0;

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

当前位置:首页 > 研究生考试


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