源码


//5.1#include<stdio.h>
#define ADJUST 7.31
int main(void)
{const double SCALE = 0.333;double shoe, foot;shoe = 9.0;foot = SCALE * shoe + ADJUST;printf("Shoe size (men's')   foot length\n");printf("%10.1f %15.2f inches\n",shoe,foot);return 0;}
//5.2
#include<stdio.h>
#define ADJUST 7.31
int main(void)
{const double SCALE = 0.333;double shoe, foot;printf("Shoe size (men's)  foot length\n");shoe = 3.0;while (shoe < 18.5){foot = SCALE * shoe * ADJUST;printf("%10.1f %15.2f inches\n",shoe, foot);shoe = shoe + 1.0;}printf("If the shoe fits, wear it.\n");return 0;
}
//5.3
#include<stdio.h>
int main(void)
{int jane, tarzan, cheeta;cheeta = tarzan = jane = 68;printf("               cheeta  tarzan   jane\n");printf("First round score %4d %8d %8d\n",cheeta, tarzan, jane);return 0;
}
//5.4
#include<stdio.h>
int main(void)
{int num = 1;while (num < 21){printf("%4d %6d\n",num, num * num);num = num + 1;}return 0;
}
//5.5
#include<stdio.h>
#define SQUARES 64
int main(void)
{const double CROP = 2E16;double current, total;int count = 1;printf("square   grains   total   ");printf("fraction of \n");printf("         added      grains   ");printf("world total\n");total = current = 1.0;printf("%4d %13.2e %12.2e %12.2e\n",count, current,total, total/CROP);while (count < SQUARES){count = count + 1;current = 2.0 * current;total = total + current;printf("%4d %13.2e %12.2e %12.2e\n",count, current,total,total/CROP);}printf("That's all.\n");return 0;
}
//5.6
#include<stdio.h>
int main(void)
{printf("integer division: 5/4 is %d \n",5/4);printf("integer division: 6/3 is %d \n",6/3);printf("integer division: 7/4 is %d \n",7/4);printf("floating division: 7./4. is %1.2f \n",7./4);printf("mixed division: 7./4 is %1.2f \n",7./4);return 0;
}
//5.7
#include<stdio.h>
int main(void)
{int top, score;top = score = -(2 + 5) * 6 + (4 + 3 * (2 + 3));printf("top = %d, score = %d\n",top, score);return 0;
}
//5.8
#include<stdio.h>
int main(void)
{int n = 0;size_t intsize;  intsize = sizeof(int);printf("n = %d, n has %zd bytes; all ints have %zd bytes.\n",n,sizeof n,intsize);return 0;
}
//5.9
#include<stdio.h>
#define SEC_PER_MIN 60
int main(void)
{int sec, min, left;printf("Convert seconds to minutes and seconds!\n");printf("Enter the number of seconds (<=0 to quit):\n");scanf("%d",&sec);while (sec>0){min = sec/SEC_PER_MIN;left = sec% SEC_PER_MIN;      // 可以通过 a - (a/b)*b 来计算 a%b .printf("%d seconds is %d minutes,%d seconds.\n",sec,min,left);printf("Enter next value(<=0 to quit):\n");scanf("%d",&sec);}printf("Done!\n");return 0;
}
//5.10
#include<stdio.h>
int main(void)
{int ultra = 0,super = 0;while (super < 5){super++;++ultra;printf("super = %d, ultra = %d \n",super, ultra);}return 0;
}
//5.11
#include<stdio.h>
int main(void)
{int a = 1, b = 1;int a_post, pre_b;a_post = a++;pre_b = ++b;printf("a    a_post b    pre_b \n");printf("%ld %5d %5d %5d\n",a,a_post,b,pre_b);return 0;
}
//5.12
#include<stdio.h>
#define MAX 100
int main(void)
{int count = MAX + 1; while(--count > 0) {printf("%d bottles of spring water on the wall, ""%d bottles of spring water!\n",count,count);printf("Take one down and pass it aroud,\n");printf("%d bottles of spring water!\n\n",count - 1);}return 0;
}
//5.13
#include<stdio.h>
int main(void)
{int count, sum;count = 0;sum = 0;while (count++ < 20)sum = sum + count;printf("sum = %d\n",sum);return 0;
}
//5.14
#include<stdio.h>
int main(void)
{char ch;int i;float fl;fl = i = ch = 'C';printf("ch = %c, i = %d, fl = %2.2f\n",ch,i,fl);ch = ch + 1;i = fl + 2 * ch;fl = 2.0 * ch + i;printf("ch = %c, i = %d, fl = %2.2f\n",ch,i,fl);ch = 1107;printf("Now ch = %c\n",ch);ch = 80.89;printf("Now ch = %c\n",ch);return 0;
}
//5.15#include<stdio.h>
void pound(int n);
int main(void)
{int times = 5;char ch = '!';float f = 6.0f;pound(times);pound(ch);pound(f);return 0;
}
void pound(int n)
{while(n-- > 0)printf("#");printf("\n");
}
//5.16
#include<stdio.h>
const int S_PER_M = 60;
const int S_PER_H = 3600;
const double M_PER_K = 0.62137;
int main(void)
{double distk, distm;double rate;int min, sec;int time;double mtime;int mmin, msec;printf("This is program converts your time for a metric race\n");printf("to a time for running a mile and to your average\n");printf("speed in miles per hour\n");printf("Please enter, in kilometers, the distance run.\n");scanf("%lf",&distk);printf("Next enter the time in minutes and seconds.\n");printf("Begin by entering the minutes.\n");scanf("%d",&min);printf("Now enter the seconds.\n");scanf("%d", &sec);time = S_PER_M * min + sec;    //把时间转化成秒 distm = M_PER_K * distk;       //把公里转换成英里 rate = distm / time * S_PER_H; //英里/秒 * 秒/小时 = 英里/小时 mtime = (double)time / distm;  //时间/距离 = 跑1英里所用的时间 mmin = (int)mtime / S_PER_M;   //求出分钟数msec = (int)mtime % S_PER_M;   //求出剩余的秒数 printf("You ran %1.2f km (%1.2f miles) in %d min, %d sec.\n",distk, distm, min, sec);printf("That pace corresponds to running a mile in %d min, ",mmin);printf("%d sec.\nYour avergae speed was %1.2f mph.\n",msec, rate);return 0;
}

C Primer Plus第六版第五章运算符,表达式,语句源码相关推荐

  1. c primer plus 第六版 第五章练习

    /* 1.编写一个程序,把用分钟表示的时间转换成用小时和分钟表示的 时间.使用#define或const创建一个表示60的符号常量或const变量.通 过while循环让用户重复输入值,直到用户输入小 ...

  2. 数据库系统概念第六版 第五章练习题 2 4

    数据库系统概念第六版 第五章练习题 2 4 5.2 写一个使用JDBC元数据特性的JAVA函数,该函数用ResultSet作为输入参数,并把结果输出为用合适的名字作为列名的表格形式. (对JAVA不太 ...

  3. 第五章运算符表达式和语句

    title: 第五章 运算符.表达式和语句 author: HardyDragon tags: C Notes 第五章 运算符.表达式和语句 5.1 循环简介 5.2 基本运算符 5.2.1 赋值运算 ...

  4. 材料力学Ⅰ(第六版)第五章课后习题答案

    第一章 绪论 第二章 拉伸.压缩与剪切 第三章 扭转 第四章 弯曲内力 第五章 弯曲应力 第六章 弯曲变形 第七章 应力和应变分析强度理论 第八章 组合变形 第九章 压杆稳定

  5. C Primer Plus(第六版)第三章 数据和C

    笔记记录 1.float 类型可以储存带小数的数字. 2.printf()中使用%f来处理浮点值.%.2f中的.2用于精确控制输出,指定输出的浮点数只显示小数点后面两位. 3.scanf()函数用于读 ...

  6. 软件工程导论第六版 第五章 总体设计知识点总结

    目录 总体设计概述 目的 任务 设计过程 设计原理 什么是模块?什么是模块化? 模块化的优点 模块化和软件成本 逐步求精 什么是逐步求精? Miller法则 抽象 信息隐藏和局部化 什么是信息隐藏 信 ...

  7. C Primer Plus第六版第七章编程题目与参考答案⭐

    1.编写一个程序读取输入,读到#字符停止,然后报告读取的空格数.换行符数和所有其他字符的数量. #include <stdio.h> #define STOP '#' #define SP ...

  8. C Primer Plus (第六版) 第七章 7.11编程练习 参考答案

    11.ABC 邮购杂货店出售的洋蓟售价为 2.05 美元/磅,甜菜售价为 1.15美元/磅,胡萝卜售价为 1.09美元/磅.在添加运费之前,100美元的订单有5%的打折优惠.少于或等于5磅的订单收取6 ...

  9. c primer plus第六版 第七章

    /*1.编写一个程序读取输入,读到#字符停止,然后报告读取的空格 数.换行符数和所有其他字符的数量.*/ #include<stdio.h> #include<ctype.h> ...

最新文章

  1. VC/MFC Tips
  2. MATLAB crc.generato,matlab中CRC的函数使用
  3. python3精要(57)-all,any,bin(转换二进制)
  4. php if判断两个条件_PHP中if相关条件语句该如何理解使用?
  5. Android 数据解析——Gson与json
  6. Unique Email Addresses
  7. IIS Web负载均衡的几种方式
  8. 如何使用Omni Remover Mac版释放Mac上的空间
  9. 邮箱显示exchange账号服务器错误,删除监视邮箱Exchange服务器不正常状态
  10. native service
  11. arduino atmega328P MCP4725 proteus 仿真 程序
  12. PCBA加工为什么要做首件检测?
  13. 苹果手机投屏到Windows
  14. android des 加密
  15. QT中主线程终止子线程中的死循环
  16. 实验三 基于A*算法的迷宫游戏
  17. 使用ch.ethz.ssh2中sess.execCommand方法导致线程卡死的原因分析
  18. Fundamental of 4G LTE - 学习笔记(3)OFDMA/OFDM in 4G LTE (Part1)
  19. php中date是啥意思,php中date函数具有哪些功能呢?
  20. 反转链表——《剑指offer》

热门文章

  1. 无需第三方软件,在 Yosemite 下给 iOS 设备轻松录屏
  2. 被市场「遗忘」的匹克体育
  3. 怎么用计算机求数值等于log,怎么用计算器上的log?
  4. vue中控制台报错[WDS] Disconnected的解决办法
  5. 调研主板,树莓派 VS RK3288板子,还是 RK的主板香,但是只支持 anrdoid 7系统,估计也有刷机成 armbian或者
  6. three.js 凹凸贴图
  7. linux安装java.jdk环境
  8. 安卓一体机开发板,安卓主板广告机
  9. 使用adb.exe禁止安卓手机app震动权限
  10. WMS 系统出入库理解