- 279
- 0
- 约2.55千字
- 约 4页
- 2023-01-13 发布于上海
- 举报
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)
Parkinsons Law:
Work expands so as to fill the time
available for its completion.
3. [was #4]
#include stdio.h
int main(void)
{
int height = 8, length = 12, width = 10, volume;
volume = height * length * width;
printf(Dimensions: %dx%dx%d\n, length, width, height);
printf(Volume (cubic inches): %d\n, volume);
printf(Dimensional weight (pounds): %d\n, (volume + 165) / 166);
return 0;
}
4. [was #6] Heres one possible program:
#include stdio.h
int main(void)
{
int i, j, k;
float x, y, z;
printf(Value of i: %d\n, i);
printf(Value of j: %d\n, j);
printf(Value of k: %d\n, k);
printf(Value of x: %g\n, x);
printf(Value of y: %g\n, y);
printf(Value of z: %g\n, z);
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 youll 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 stdio.h
int main(void)
{
float original_amount, amount_with_tax;
printf(Enter an amount: );
scanf(%f, original_amount);
amount_with_tax = original_amount * 1.05f;
printf(With tax added: $%.2f\n, amount_with_tax);
return 0;
}
The amount_with_tax variable is unnecessary. If we remove it, the program is slightly shorter:
#include stdio.h
int main(void)
{
float original_amount;
printf(Enter an amount: );
scanf(%f, original_amount);
printf(With tax added: $%.2f\n, original_amount * 1.05f);
return 0;
}
Chapter 3
Answers to Selected Exercises
2.
您可能关注的文档
最近下载
- 心脑血管的危害和防治.ppt
- 上海2024年高考英语试卷.doc VIP
- 2026春新版人教版八年级下册单词默写单词表(全)U1-U8中译英.docx
- 07 王涛-教师资格-数学学科知识与教学能力(高中)-第三部分第五章至第八章(46-48讲).pdf VIP
- 《业财一体化实训教程-----金蝶云星空V7.5》.pptx VIP
- 2014广东粤西北事业单位考试真题及答案——通用类.doc VIP
- 基于PLC的运料小车自动控制设计研究.docx VIP
- ISO 9001(DIS)-2026《质量管理体系——要求》(含附录使用指南-中文版-译-2025年9月).docx VIP
- 《宋代点茶文化与艺术》全套教学课件.pptx
- 年产3000吨猕猴桃果汁工厂设计_毕业设计.doc VIP
原创力文档

文档评论(0)