第一范文网 - 专业文章范例文档资料分享平台

c语言程序设计现代方法(第二版)习题答案

来源:用户分享 时间:2025/9/3 21:08:05 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

Chapter 2

Answers to Selected Exercises

2. [was #2] (a) The program contains one directive (#include) and four statements (three calls of printf and one return). (b)

Parkinson's Law:

Work expands so as to fill the time available for its completion. 3. [was #4]

#include

int main(void) {

int height = 8, length = 12, width = 10, volume;

volume = height * length * width;

printf(\ printf(\

printf(\

return 0; }

4. [was #6] Here's one possible program: #include

int main(void) {

int i, j, k; float x, y, z;

printf(\ printf(\ printf(\

printf(\ printf(\

printf(\

return 0; }

When compiled using GCC and then executed, this program produced the following output: Value of i: 5618848 Value of j: 0

Value of k: 6844404 Value of x: 3.98979e-34 Value of y: 9.59105e-39 Value of z: 9.59105e-39

The values printed depend on many factors, so the chance that you'll get exactly these numbers is small.

5. [was #10] (a) is not legal because 100_bottles begins with a digit. 8. [was #12] There are 14 tokens: a, =, (, 3, *, q, -, p, *, p, ), /, 3, and ;.

Answers to Selected Programming Projects 4. [was #8; modified]

#include

int main(void) {

float original_amount, amount_with_tax;

printf(\ scanf(\

amount_with_tax = original_amount * 1.05f;

printf(\

return 0; }

The amount_with_tax variable is unnecessary. If we remove it, the program is slightly shorter: #include

int main(void) {

float original_amount;

printf(\ scanf(\

printf(\

return 0; }

Chapter 3

Answers to Selected Exercises 2. [was #2]

(a) printf(\(b) printf(\(c) printf(\(d) printf(\

5. [was #8] The values of x, i, and y will be 12.3, 45, and .6, respectively. Answers to Selected Programming Projects 1. [was #4; modified]

#include

int main(void) {

int month, day, year;

printf(\ scanf(\

printf(\

return 0; }

3. [was #6; modified]

#include

int main(void) {

int prefix, group, publisher, item, check_digit;

printf(\

scanf(\&check_digit);

printf(\

printf(\ printf(\ printf(\

printf(\

/* The five printf calls can be combined as follows:

printf(\code: %d\\nItem number: %d\\nCheck digit: %d\\n\

prefix, group, publisher, item, check_digit); */

return 0; }

Chapter 4

Answers to Selected Exercises

2. [was #2] Not in C89. Suppose that i is 9 and j is 7. The value of (-i)/j could be either –1 or –2, depending on the implementation. On the other hand, the value of -(i/j) is always –1, regardless of the implementation. In C99, on the other hand, the value of (-i)/j must be equal to the value of -(i/j). 9. [was #6] (a) 63 8 (b) 3 2 1 (c) 2 -1 3 (d) 0 0 0

c语言程序设计现代方法(第二版)习题答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4msjf81dzc4m0xd0pdsf_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top