欢迎来到冰豆网! | 帮助中心 分享价值,成长自我!
冰豆网
全部分类
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • 党团工作>
  • ImageVerifierCode 换一换
    首页 冰豆网 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    c语言程序设计现代方法习题答案.docx

    • 资源ID:8381459       资源大小:36.10KB        全文页数:90页
    • 资源格式: DOCX        下载积分:12金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要12金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    c语言程序设计现代方法习题答案.docx

    1、c语言程序设计现代方法习题答案Chapter 2Answers to Selected Exercises2. 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 timeavailable for its completion.3. was #4#include int main(void)int height = 8

    2、, length = 12, width = 10, volume;volume = height * length * width;printf(Dimensions: %dx%dx%dn, length, width, height);printf(Volume (cubic inches): %dn, volume);printf(Dimensional weight (pounds): %dn, (volume + 165) / 166);return 0;4. was #6 Heres one possible program:#include int main(void)int i

    3、, j, k;float x, y, z;printf(Value of i: %dn, i);printf(Value of j: %dn, j);printf(Value of k: %dn, k);printf(Value of x: %gn, x);printf(Value of y: %gn, y);printf(Value of z: %gn, z);return 0;When compiled using GCC and then executed, this program produced the following output:Value of i: 5618848Val

    4、ue of j: 0Value of k: 6844404Value of x: 3.98979e-34Value of y: 9.59105e-39Value of z: 9.59105e-39The 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:

    5、 a, =, (, 3, *, q, -, p, *, p, ), /, 3, and ;.Answers to Selected Programming Projects4. was #8; modified#include int main(void)float original_amount, amount_with_tax;printf(Enter an amount: );scanf(%f, &original_amount);amount_with_tax = original_amount * ;printf(With tax added: $%n, amount_with_ta

    6、x);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(Enter an amount: );scanf(%f, &original_amount);printf(With tax added: $%n, original_amount * );return 0;Chapter 3Answers to Selected Exercises

    7、2. was #2(a) printf(%-8.1e, x); (b) printf(%10.6e, x); (c) printf(%, x); (d) printf(%, x);5. was #8 The values of x, i, and y will be 12.3, 45, and .6, respectively.Answers to Selected Programming Projects1. was #4; modified#include int main(void)int month, day, year;printf(Enter a date (mm/dd/yyyy)

    8、: );scanf(%d/%d/%d, &month, &day, &year);printf(You entered the date %d%.2d%.2dn, year, month, day);return 0;3. was #6; modified#include int main(void)int prefix, group, publisher, item, check_digit;printf(Enter ISBN: );scanf(%d-%d-%d-%d-%d, &prefix, &group, &publisher, &item, &check_digit);printf(G

    9、S1 prefix: %dn, prefix);printf(Group identifier: %dn, group);printf(Publisher code: %dn, publisher);printf(Item number: %dn, item);printf(Check digit: %dn, check_digit);/* The five printf calls can be combined as follows:printf(GS1 prefix: %dnGroup identifier: %dnPublisher code: %dnItem number: %dnC

    10、heck digit: %dn,prefix, group, publisher, item, check_digit);*/return 0;Chapter 4Answers to Selected Exercises2. 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, regardl

    11、ess 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 013. was #8 The expression +i is equivalent to (i += 1). The value of both expressions is i after the increment has been performed.Answers to

    12、Selected Programming Projects2. was #4#include int main(void)int n;printf(Enter a three-digit number: );scanf(%d, &n);printf(The reversal is: %d%d%dn, n % 10, (n / 10) % 10, n / 100);return 0;Chapter 5Answers to Selected Exercises2. was #2(a) 1 (b) 1 (c) 1 (d) 14. was #4 (i j) - (i j)6. was #12 Yes,

    13、 the statement is legal. When n is equal to 5, it does nothing, since 5 is not equal to 9.10. was #16 The output isonetwosince there are no break statements after the cases.Answers to Selected Programming Projects2. was #6#include int main(void)int hours, minutes;printf(Enter a 24-hour time: );scanf

    14、(%d:%d, &hours, &minutes);printf(Equivalent 12-hour time: );if (hours = 0)printf(12:%.2d AMn, minutes);else if (hours 12)printf(%d:%.2d AMn, hours, minutes);else if (hours = 12)printf(%d:%.2d PMn, hours, minutes);elseprintf(%d:%.2d PMn, hours - 12, minutes);return 0;4. was #8; modified#include int m

    15、ain(void)int speed;printf(Enter a wind speed in knots: );scanf(%d, &speed);if (speed 1)printf(Calmn);else if (speed = 3)printf(Light airn);else if (speed = 27)printf(Breezen);else if (speed = 47)printf(Galen);else if (speed = 63)printf(Stormn);elseprintf(Hurricanen);return 0;6. was #10#include int m

    16、ain(void)int check_digit, d, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5,first_sum, second_sum, total;printf(Enter the first (single) digit: );scanf(%1d, &d);printf(Enter first group of five digits: );scanf(%1d%1d%1d%1d%1d, &i1, &i2, &i3, &i4, &i5);printf(Enter second group of five digits: );scanf(%1d%1d

    17、%1d%1d%1d, &j1, &j2, &j3, &j4, &j5);printf(Enter the last (single) digit: );scanf(%1d, &check_digit);first_sum = d + i2 + i4 + j1 + j3 + j5;second_sum = i1 + i3 + i5 + j2 + j4;total = 3 * first_sum + second_sum;if (check_digit = 9 - (total - 1) % 10)printf(VALIDn);elseprintf(NOT VALIDn);return 0;10.

    18、 was #14#include int main(void)int grade;printf(Enter numerical grade: );scanf(%d, &grade);if (grade 100) printf(Illegal graden);return 0;switch (grade / 10) case 10:case 9: printf(Letter grade: An);break;case 8: printf(Letter grade: Bn);break;case 7: printf(Letter grade: Cn);break;case 6: printf(Le

    19、tter grade: Dn);break;case 5:case 4:case 3:case 2:case 1:case 0: printf(Letter grade: Fn);break;return 0;Chapter 6Answers to Selected Exercises4. was #10 (c) is not equivalent to (a) and (b), because i is incremented before the loop body is executed.10. was #12 Consider the following while loop:whil

    20、e () continue;The equivalent code using goto would have the following appearance:while () goto loop_end;loop_end: ; /* null statement */12. was #14for (d = 2; d * d = n; d+)if (n % d = 0)break;The if statement that follows the loop will need to be modified as well:if (d * d = n)printf(%d is divisibl

    21、e by %dn, n, d);elseprintf(%d is primen, n);14. was #16 The problem is the semicolon at the end of the first line. If we remove it, the statement is now correct:if (n % 2 = 0)printf(n is evenn);Answers to Selected Programming Projects2. was #2#include int main(void)int m, n, remainder;printf(Enter t

    22、wo integers: );scanf(%d%d, &m, &n);while (n != 0) remainder = m % n;m = n;n = remainder;printf(Greatest common divisor: %dn, m);return 0;4. was #4#include int main(void)float commission, value;printf(Enter value of trade: );scanf(%f, &value);while (value != ) if (value )commission = + * value;else i

    23、f (value )commission = + * value;else if (value )commission = + * value;else if (value )commission = + * value;else if (value )commission = + * value;elsecommission = + * value;if (commission )commission = ;printf(Commission: $%nn, commission);printf(Enter value of trade: );scanf(%f, &value);return

    24、0;6. was #6#include int main(void)int i, n;printf(Enter limit on maximum square: );scanf(%d, &n);for (i = 2; i * i = n; i += 2)printf(%dn, i * i);return 0;8. was #8#include int main(void)int i, n, start_day;printf(Enter number of days in month: );scanf(%d, &n);printf(Enter starting day of the week (

    25、1=Sun, 7=Sat): );scanf(%d, &start_day);/* print any leading blank dates */for (i = 1; i start_day; i+)printf( );/* now print the calendar */for (i = 1; i = n; i+) printf(%3d, i);if (start_day + i - 1) % 7 = 0)printf(n);return 0;Chapter 7Answers to Selected Exercises3. was #4 (b) is not legal.4. was

    26、#6 (d) is illegal, since printf requires a string, not a character, as its first argument.10. was #14 unsigned int, because the (int) cast applies only to j, not j * k.12. was #16 The value of i is converted to float and added to f, then the result is converted to double and stored in d.14. was #18

    27、No. Converting f to int will fail if the value stored in f exceeds the largest value of type int.Answers to Selected Programming Projects1. was #2 short int values are usually stored in 16 bits, causing failure at 182. int and long int values are usually stored in 32 bits, with failure occurring at

    28、46341.2. was #8#include int main(void)int i, n;char ch;printf(This program prints a table of squares.n);printf(Enter number of entries in table: );scanf(%d, &n);ch = getchar();/* dispose of new-line character following number of entries */* could simply be getchar(); */for (i = 1; i = n; i+) printf(%10d%10dn, i, i * i);if (i % 24 = 0) printf(Press Enter to continue.);ch = getchar(); /* or simply getchar(); */return 0;5. was #10#include #include int main(void)int sum = 0;char ch;printf(Enter a word: );while (ch = getchar() != n)switch (toupper(c


    注意事项

    本文(c语言程序设计现代方法习题答案.docx)为本站会员主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2022 冰点文档网站版权所有

    经营许可证编号:鄂ICP备2022015515号-1

    收起
    展开