新编c语言程序设计(周二强版)课后习题练习4答案

上传人:aa****6 文档编号:37605141 上传时间:2018-04-19 格式:DOC 页数:13 大小:492KB
返回 下载 相关 举报
新编c语言程序设计(周二强版)课后习题练习4答案_第1页
第1页 / 共13页
新编c语言程序设计(周二强版)课后习题练习4答案_第2页
第2页 / 共13页
新编c语言程序设计(周二强版)课后习题练习4答案_第3页
第3页 / 共13页
新编c语言程序设计(周二强版)课后习题练习4答案_第4页
第4页 / 共13页
新编c语言程序设计(周二强版)课后习题练习4答案_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《新编c语言程序设计(周二强版)课后习题练习4答案》由会员分享,可在线阅读,更多相关《新编c语言程序设计(周二强版)课后习题练习4答案(13页珍藏版)》请在金锄头文库上搜索。

1、练习练习 4 44.1 C 语言中“真”和“假”的编码有何特点?e 为整型变量,!e 与 e != 1 等价吗?与 e = 0 等价吗?答:C 语言中“真”和“假”的编码简单地说,0 表示“假” ,非 0 代表“真” 。在逻辑运算时如此,0 表示“假” ,非 0 代表“真” 。不过需注意,在表示逻辑运算结果时, “假”为 0, “真”为 1。当 e 为 0 时,!e 的值为 1;e != 1 的值为 0; e = 0 的值为 1。当 e 为非 0 时,!e 的值为 0;e != 1 的值可能(e 不等于 0 也不等于 1 时)为 0,可能(e 等于 1 时)为 1, ; e = 0 的值为 0

2、。反之,e = 0 的值为 0 时,e 为非 0,!e 的值也为 0。e = 0 的值为 1 时,e 为 0,!e 的值也为 1。综上所述:!e 与 e != 1 不等价,与 e = 0 等价。4.2 C 语言中逻辑量的编码特点对算术运算和逻辑运算有何影响?答:由于没有专门的逻辑类型,C 语言中的算术运算和逻辑运算可以“混合” ,如!5*3,而类似的表达式往往没有什么实际意义。4.3 给出逻辑或|和逻辑非!的真值表。答:逻辑或|的真值表a 的值b 的值a | b 的值真(非 0)真(非 0)真(1)真(非 0)假(0)真(1)假(0)真(非 0)真(1)假(0)假(0)假(0)逻辑非!的真值表

3、a 的值!a 的值真(非 0)假(0)假(0)真(1)4.4 计算下面各逻辑表达式的值,其中字母均为变量,且 a=2,b=3,c=5。1. a * b c return;4.8 输入一个小写字母,将字母循环后移 3 个位置后输出。如a变成d,y变成b。 (用 if 结构实现而非表达式((ch + 3 - a) % 26 + a)答:4.9 画出下面程序的流程图。程序有几条可执行路径?每条可执行路径分别对应什么样的输入数据?#include void main( )int x, y, z = 0;scanf(“%d%d“, if(x 0)z = x + y;if(y 0)z = x - y;pr

4、intf(“x=%d,y=%d,z=%dn“, x, y, z);开始输入x、yx0z=x+yTFy0z=x-yTF输出x、y和z结束T可见程序有 4 条可执行路径。第一条:x0 且 y0 时程序的执行路径(如输入数据为 2、3 时) ;第二条:x0 且 y0 时程序的执行路径(如输入数据为-2、5 时) ;第四条:xvoid main( )int x = 12, y = 5, z = 8;int max;max = x void main( )int x,i;float y;scanf(“%d“, else i= ;switch(i)case 0:y = x;break;case 1:cas

5、e 2:y = 10;break;case 3:case 4:y = 30 - 0.5 * x; break;case 5:y = 50;break;default:y = -1;break;if( )printf(“y=%3.1fn“, y);elseprintf(“输入错误!n“);答:x = 50i / 10y != -14.17 用 break 语句退出 switch 结构后,程序将如何执行呢?分析下面程序的输出。#include void main( )int a = 2, b = 3;switch(a 0)case 1: switch(b void main( )int a, b,

6、 c;printf(“a=“); scanf (“%d“, printf(“b=“); scanf (“%d“, printf(“c=“); scanf (“%d“, if(a = 90输出ATFgrade = 80输出BTFgrade = 70输出CTFgrade = 60输出DTF输出E图 4-14 例 4-19 的 if-else 结构答:输出 A、B、C、D、E 时各比较了 2、2、2、3、3 次。4.24 某专卖店销售运动服,若买的不少于 30 套,每套 120 元;不足 30 套的,每套 150 元;只买上衣每件 90 元;只买裤子每条 80 元。编程实现当输入所买上衣和裤子的件数

7、时输出应付款。注意:当输入 23 和 32 时,应按 23 套运动服和 9 条裤子计算应付款。答:4.25 编程实现输入方程 ax2+bx+c0 的系数时输出方程的根。注意区分以下情况:1. 方程有无数个根(abc0)2. 方程无根(ab0,c0)3. 方程只有一个实根(a0,b0)4. 方程有两个实根(判断两根是否相等) 。5. 方程有两个虚根(输出 32i 形式的虚根) 。答:4.26 输入三角形的三条边,根据情况输出以下信息中的一种。1. 可以组成等边三角形2. 可以组成等腰三角形3. 可以组成等腰直角三角形(测试数据 2.3,3.,2.3)4. 可以组成一般直角三角形5. 可以组成一般

8、三角形6. 不能组成三角形。答:AcknowledgementsMy deepest gratitude goes first and foremost to Professor aaa , my supervisor, for her constant encouragement and guidance. She has walked me through all the stages of the writing of this thesis. Without her consistent and illuminating instruction, this thesis could n

9、ot havereached its present form.Second, I would like to express my heartfelt gratitude to Professor aaa, who led me into the world of translation. I am also greatly indebted to the professors and teachers at the Department of English: Professor dddd, Professor ssss, who have instructed and helped me

10、 a lot in the past two years.Last my thanks would go to my beloved family for their loving considerations and great confidence in me all through these years. I also owe my sincere gratitude to my friends and my fellow classmates who gave me their help and time in listening to me and helping me work

11、out my problems during the difficult course of the thesis.My deepest gratitude goes first and foremost to Professor aaa , my supervisor, for her constant encouragement and guidance. She has walked me through all the stages of the writing of this thesis. Without her consistent and illuminating instru

12、ction, this thesis could not havereached its present form.Second, I would like to express my heartfelt gratitude to Professor aaa, who led me into the world of translation. I am also greatly indebted to the professors and teachers at the Department of English: Professor dddd, Professor ssss, who hav

13、e instructed and helped me a lot in the past two years.Last my thanks would go to my beloved family for their loving considerations and great confidence in me all through these years. I also owe my sincere gratitude to my friends and my fellow classmates who gave me their help and time in listening to me and helping me work out my problems during the difficult course of the thesis.

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

当前位置:首页 > 学术论文 > 毕业论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号