#define R #define PI main() { float s, v; s=4*PI*R*R; v=3*PI*R*R*R; printf(\volume is: %.2f.\\n\} Output
The surface area of the ball (radius is is: , and the volume .
3-7 给定x、y和z的值,编写程序,使x等于y的值,y等于z的值,z等于x的值。 Program #include <> main() { int x=1, y=2, z=3, t; printf(\ t=x; x=y; y=z; z=t; /*变量t的作用是什么*/ printf(\} Output
Before swap: x=1, y=2, z=3. After swap: x=2, y=3, z=1.
3-8 编写一个程序,给定一个浮点数(例如),显示该数的十位数字与个位数字之和
(例如5+6=11)。
Program (1) #include <> main() { float f=; int n, a, b; n=f; a = n; /*赋值后,a是什么值*/ b = n/10; /*赋值后,b是什么值*/ printf(\= %d.\\n\}
Program (2) #include <> main() { float f=; int n, a, b; n=f; a = n; b = n0/10; /*该语句与上面程序不同,看看有何区别*/ printf(\= %d.\\n\} Output
The sum of the tens digit and units digit of is: 5+ 6 = 11. 3-9 某种物品每年折旧费的计算方法如下: 3-10
折旧费?购买价格?废品价值
使用年限3-11 编写一个程序,当给定某物品的购买价格、使用年限和每年的折旧费时,计算出
其废品价值。
Program #include <> main() { float price=, year=3, depreciation=, value; value = price - year*depreciation; printf(\} Output
The scrap value is .
3-12 在库存管理中,某单个物品的经济定购数EOQ由下面等式给定: 3-13
EOQ?2?需求率?生产成本
单位时间内每种物品的储备成本3-14 而最优的定购时间间隔TBO由下面等式给定: 3-15
TBO?2?生产成本
需求率?单位时间内每种物品的储备成本
3-16 编写程序,给定需求率(单位时间内的物品数)、生产成本(每个定购)和储备
成本(单位时间内每种物品),计算EOQ和TBO。
Program #include <> #include <> main() { int demand=1000; float product_cost=, storage_cost=, eoq, tbo; eoq=sqrt(2*demand*product_cost/storage_cost); tbo=sqrt(2*product_cost/demand/storage_cost); printf(\} Output
EOQ is , and TBO is .
? 第4章 输入输出操作管理
4-1 输入两个数,将它们交换后输出。
Program #include <> main() { int x, y, t; printf(\ scanf(\ printf(\ t=x; x=y; y=t; printf(\} Output
Please input 2 numbers: 3 5 */
Before swap, the 2 numbers are: 3, 5 After swap, the 2 numbers are: 5, 3
/* Blue is input
4-2 输入一个十进制数,输出对应的八进制数和十六进制数。
Program #include <> main() { int n; printf(\ scanf(\ printf(\} Output
Please input a decimal number: 10 */
The octal is 12, and the hexadecimal is a. 考虑:如何得到下面的输出
Please input a decimal number: 10 */
The octal is 012, and the hexadecimal is 0xa.
/* Blue is input
/* Blue is input
4-3 编写程序,输入3个整数,计算并输出它们的平均值。 Program #include <> main() { int a, b, c; printf(\ scanf(\ printf(\} Output
Please input 3 integers: 4 7 -19 */
The average is .
/* Blue is input
4-4 编写一个程序,读取x和y的值,显示下面表达式的值: 4-5 (1)4-6 (2)
x?y x?yx?y 24-7 (3)?x?y??x?y?
Program #include <> main() { float x, y; printf(\ scanf(\ printf(\ printf(\ printf(\} Output
Please input x and y: (1) (x+y)/(x-y) = (2) (x+y)/2 = (3) (x+y)(x-y) =
/* Blue is input */
4-8 计算银行存款的本息。编写程序,输入存款金额money、存期year和年利率rate,
根据下列公式计算存款到期时的本息合计sum(税前),输出时保留两位小数。