2022年c语言设计谭浩强第三版的课后习题答案 .pdf
《2022年c语言设计谭浩强第三版的课后习题答案 .pdf》由会员分享,可在线阅读,更多相关《2022年c语言设计谭浩强第三版的课后习题答案 .pdf(45页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、c 语言设计谭浩强第三版的课后习题答案( 一) (C language design Tan Haoqiang third edition of after-school exercise answers (1) )C language design Tan Haoqiang third edition of after-school Exercises answer (1) 1.5, please refer to this chapter example, write a C program, output the following information: The government
2、 Very Goodj! The government Solution: (main) Printf (n government); Printf (n); Printf (Very Good, n); Printf (n); Printf (*n); 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 1 页,共 45 页 - - - - - - - - - 1.6 write a program, enter a, B, C three values, the o
3、utput of which the largest. Solution: Main () int, a, B, C, max; Printf (enter three numbers a, B, c:n); Scanf (%d,%d,%d, &a, &b, &c); Max=a; If (maxb) Max=b; If (maxc) Max=c; Printf (maximum number:%d, Max); Third chapters 3.3. Please indicate the following numbers in octal and sixteen 名师归纳总结 精品学习资
4、料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 2 页,共 45 页 - - - - - - - - - decimal numbers: (1) 10 (2), 32 (3), 75 (4), -617 (5) -111 (6) 2483 (7) -28654 (8) 21003; Solution: eighteen, sixteen (10) = (12) = (a) (32) = (40) =20 (75) = (113) =4b (-617) = (176627) =fd97 -
5、111=177621=ff91 2483=4663=963 -28654=110022=9012 21003=51013=520b What is the difference between a 3.5 character constant and a string literal? Solution: a literal constant is a character enclosed in single quotes. String literals are made up of 0 or more characters Instead, wrap them in double quot
6、es and automatically add an 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 3 页,共 45 页 - - - - - - - - - ending symbol 0. to the string at the end of storage 3.6 write down the running results of the following programs: #include Void, main () Char, c1=a, c2=b
7、, c3=c, c4=101, c5=116; Printf (a%c b%ctc%ctabcn, C1, C2, C3); Printf (tb%c%cn, C4, C5); Solution: the result of the program is: AABB CC ABC A N 3.7, China into the password. Password Law: use the original letter after the fourth letters instead of the original letter, For example, the letter A is f
8、ollowed by the fourth letter E and E instead of A. Therefore, China should be translated as Glmre Please compile a program that uses the initial value agenda to make C1, C2, C3, C4, C5,G,1,m,r,e, and 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 4 页,共 45 页
9、- - - - - - - - - Output (main) char, c1=, C, c2=, h, c3=, I, c4=n, c5=a; C1+=4; C2+=4; C3+=4; C4+=4; C5+=4; Printf (the password is%c%c%c%c%cn, C1, C2, C3, C4, C5); Can the 3.8 case 3.6 be changed as follows?: #include Void, main () Int, C1, C2; (formerly char, C1, C2) 名师归纳总结 精品学习资料 - - - - - - - -
10、 - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 5 页,共 45 页 - - - - - - - - - C1=97; C2=98; Printf (%c%cn, C1, C2); Printf (%d%dn, C1, C2); Solution: Yes, because in the output character range, the use of integer and character type is the same 3.9 find the value of the following arithmeti
11、c expression (1) x+a%3* (int) (x+y),%2/4=2.5 (x=2.5, a=7, y=4.7) (2) (float) (a+b), /2+ (int), x% (int), y=3.5 (a=2, b=3, x=3.5, y=2.5) 3.10 write down the running results of the following program: #include Void, main () Int, I, J, m, n; I=8; 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料
12、- - - - - - - - - - - - - - - 第 6 页,共 45 页 - - - - - - - - - J=10; M=+i; N=j+; Printf (%d,%d,%d,%dn, I, J, m, n); Results: 9,11,9,10 Fourth chapters 4.4.a=3, b=4, c=5, x=1.2, y=2.4, z=-3.6, u=51274, n=128765, c1=a, c2=b. wanted to To the following output format and results, please write the program
13、requirements output as follows: A= 3, b= 4, c= 5 X=1.200000, y=2.400000, z=-3.600000 X+y= 3.60, y+z=-1.20, z+x=-2.40 U= 51274 n= 128765 C1=aor 97 (ASCII) 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 7 页,共 45 页 - - - - - - - - - C2=Bor 98 (ASCII) Solution:
14、(main) Int, a, B, c; Long, int, u, n; Float, x, y, z; char c1, c2; a = 3; b = 4; c = 5; x = 1.2; y = 2.4; z = 3.6; d = 51274; n = 128765; c1 = a; c2 = b; printf ( n); printf (a = b =% 2d 2d c =% 2d n, a, b, c); printf (x =% 8.6f, y =% 8.6f, z =% 9.6f n , x, y, z); printf (x + y =% 5.2f y = z =% 5.2f
15、 z + x =% 5.2f n x + y, 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 8 页,共 45 页 - - - - - - - - - y + z, z + x); printf (d =% 6ld n =% 9ld n, d, n); printf (c1 = % c or% d (ascii) n, c1, c2); printf (c2 = % c or% d (ascii) n , c2, c2); 4.5 请写出下面程序的输出结果. 结果
16、: 57 5 7 67.856400, -789.123962 67.856400, -789.123962 67.86, 789.12,67.856400, 789.123962,67.856400, -789.123962 6.785640e + 001, -7.89e + 002 a 65101,41 12345674553207, d687 6553517777, ffff, - 1 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 9 页,共 45 页 -
17、- - - - - - - - computer, com 4.6 用下面的 scanf 函数输入数据 , 使 a = 3, b = 7 x = 8.5, y = 71.82, c1 = a, c = a 问在键盘上如何输入 ? main () int a, b; float x, y; char c1, c2; scanf (a =% d b =% d, & a & b); scanf (x =% f y =% e , & x & y); scanf (c1 = c2 =% c% c, & c1 & c2); 解: 可按如下方式在键盘上输入: a = 3, b = 7 x = y = 71.
18、82 8.5 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 10 页,共 45 页 - - - - - - - - - c1 = a c2 = a 说明: 在边疆使用一个或多个scnaf 函数时, 第一个输入行末尾输入的 回车 被第二个 scanf 函数吸收 , 因此在第二 三个 scanf 函数的双引号后设一个空格以抵消上行入的 回车. 如果没有这个空格 , 按上面输入数据会出错 , 读者目前对此只留有一初步概念即可 , 以后再进一步深入理解 . 4.7 用下面
19、的 scanf 函数输入数据使a = 10, b = 20, c1 = a, c = a, x = 1.5, y = - 3.75, z = 57.8, 请问在键盘上如何输入数据 ? scanf (% 5d% 5d% c% c% f% f% * f% f, & a & b & c1 & c2, & y & z); 解: main () int a, b; float x, y, z; 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 11 页,共 45 页 - - -
20、 - - - - - - char c1, c2; scanf (% 5d% 5d% c% c% f% f, & a & b & c1 & c2, & x & y & z); 运行时输入 : 10 20aa1.5 -3.75 + 1.5,67.8 注解: 按% 5d格式的要求输入 a 与 b 时, 要先键入三个空格 , 而后再打入 10 与 20.% * f是用来禁止赋值的 . 在输入时 , 对应于 % * f的地方 , 随意打入了一个数1.5, 该值不会赋给任何变量 . 3.8 设圆半径 r = 1.5, 圆柱高 h = 3, 求圆周长 , 圆面积 , 圆球表面积, 圆球体积 , 圆柱体积
21、, 用 scanf 输入数据 , 输出计算结果 , 输出时要求有文字说明 , 取小数点后两位数字 . 请编程. 解: main () float pi, h, r, l, s, sq, vq, vz; pi = 3.1415926; printf (请输入圆半径 r 圆柱高 h: n); scanf (% f,% f, & r & h); 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 12 页,共 45 页 - - - - - - - - - l = 2 * pi
22、 * r; s = r * r * pi; sq = 4 * pi * r * r; vq = 4.0 / 3.0 * pi * r * r * r; vz = pi * r * r * h; printf (圆周长为 : =% 6.2f n l); printf (圆面积为 : =% 6.2f n, s); printf (圆球表面积为 : =% 6.2f n, sq); printf (圆球体积为 : =% 6.2f n, vz); 4.9 输入一个华氏温度 , 要求输出摄氏温度 , 公式为 c = 5 / 9 (f - 32), 输出要有文字说明 , 取两位小数 . 解: main ()
23、 float c, f; printf (请输入一个华氏温度 : n); 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 13 页,共 45 页 - - - - - - - - - scanf (% f, & f); c = (5.0 / 9.0) * (f - 32); printf (摄氏温度为 :% 5.2f n, (c); 第五章 逻辑运算和判断选取结构5.4 有三个整数 a, b, c, 由键盘输入 , 输出其中最大的数 . main () int a,
24、b C; Printf (enter three numbers:); Scanf (%d,%d,%d, &a, &b, &c); If (ab) If (bc) Printf (max=%dn, C); Else 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 14 页,共 45 页 - - - - - - - - - Printf (max=%dn, B); Else if (ab) a:b; Max= (tempc) temp:c; Printf (the m
25、aximum number in A, B, C is%d, Max); 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -精心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 15 页,共 45 页 - - - - - - - - - 5.5 main () int, x, y; Printf (enter x:); Scanf (%d, &x); If (x1) y=x; Printf (X-%d, Y=X=%d, n, x, y); Else if (x9999) Place=5; Else if (num999)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年c语言设计谭浩强第三版的课后习题答案 2022 语言 设计 谭浩强 第三 课后 习题 答案
限制150内