当作复习。。。

(1)将华氏度 换算成 摄氏度,公式:

℃=(5/9)(̧°F-32)
#include <stdio.h>

int transformTemprature(int F){
//`C=(5/9)(̧`F-32)
return (int)( * (F-) / );
} int main(){ int lower = ;
int upper = ;
int step = ; for(int f=lower; f<=upper; f+=step){
printf("%d %d\n",f,transformTemprature(f));
} return ;
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ vim Temprature.c
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ cc -std=gnu99 Temprature.c
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ a.out
-
- 修改为
printf("%d\t%d\n",f,transformTemprature(f));
加入制表符 \t lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ vim Temprature.c
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ cc -std=gnu99 Temprature.c
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ a.out
-
- 修改为
printf("%3d%3d\n",f,transformTemprature(f));
右对齐 lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ vim Temprature.c
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ cc -std=gnu99 Temprature.c
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ a.out
-
-

(2)为了使精度更高。将变量由int 改为 float

#include <stdio.h>

float transformTemprature(int F){
//`C=(5/9)(̧`F-32)
return (5.0/9.0) * (F-32.0);
} int main(){ float lower = ;
float upper = ;
float step = ; for(float f=lower; f<=upper; f+=step){
printf("%3.0f%6.1f\n",f,transformTemprature(f));
} return ;
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ vim TempratureFloat.c
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ cc -std=gnu99 TempratureFloat.c
lenovo-myc@lenovomyc-Lenovo-Product:~/C_test$ a.out
-17.8
-6.7
4.4
15.6
26.7
37.8
48.9
60.0
71.1
82.2
93.3
104.4
115.6
126.7
137.8
148.9

(3)去掉多余参数

#include <stdio.h>

float transformTemprature(int F){
//`C=(5/9)(̧`F-32)
return (5.0/9.0) * (F-32.0);
} int main(){ for(int f=; f<=; f+=){
printf("%3d%6.1f\n",f,transformTemprature(f));
} return ;
}

(4) 将 幻数  替换为 #define 符号常量

#include <stdio.h>

#define LOWWER 0   /* lower limit of table */
#define UPPER 300  /* upper limit */
#define STEP 20   /* step size */ float transformTemperature(int f){
return (5.0/9.0) * (f - 32.0);
} /* print Fahrenheit-Celsius table */
int main(){
for(int f=LOWWER; f<=UPPER; f+=STEP){
printf("%3d%6.1f\n",f,transformTemperature(f));
} return ;
}

C程序设计语言(K&R) 笔记1的更多相关文章

  1. C程序设计语言(K&R)笔记

    1.表达式中float类型的操作数不会自动转换为double类型.一般来说,数学函数(如math.h)使用双精度类型的变量.使用float类型主要是为了在使用较大数组时节省存储空间,有时也为了节省机器 ...

  2. 《C程序设计语言》读书笔记----习题1-21

    题目就不写了,大概意思就是:尽量用制表符'\t'替换掉字符串中的空格. 同学们需要注意的是,打印一个制表符'\t',其所占长度不是固定的. 这里要理解“制表符”和“制表符终止位”.“制表符”的作用是使 ...

  3. 《Go程序设计语言》读书笔记-函数

    函数包含连续执行的语句,可以使用代码中通过调用函数来执行他们,函数能够将一个复杂的工作切分成多个更小的模块,使多人写作变得容易.另外,函数对他的使用者隐藏了实现细节.这几方面的特性使得函数成为多数编程 ...

  4. 《c程序设计语言》读书笔记--字符串比较

    举例如下: char a[10]; 1.定义的时候直接用字符串赋值 char a[10]="hello"; 注意:不能先定义再给它赋值,如  char a[10];  a[10]= ...

  5. 《c程序设计语言》读书笔记-5.6-指针重写getline等函数

    #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> ...

  6. 《c程序设计语言》读书笔记-4.1-判断字符串在另一个字符串中的位置

    #include <io.h> #include <stdio.h> #include <string.h> #include <stdlib.h> # ...

  7. 《c程序设计语言》读书笔记-第二个字符串任意一个在第一个字符串出现的位置,未出先返回-1

    #include <stdio.h> #include <string.h> #define Num 1000 int main() { int c,i,j = 0,m = 0 ...

  8. 《c程序设计语言》读书笔记-字符型0-9转为数字0-9

    #include <stdio.h> #define Num 10 int atoi(char s[]); int main() { int c,i = 0; char s[Num]; i ...

  9. 《c程序设计语言》读书笔记-十六位进制数转十进制

    #include <stdio.h> #include <stdio.h> int htoi(char s[]); main() { char s1[] = "10& ...

  10. 《c程序设计语言》读书笔记--闰年和字符输入不用 && ||

    #include <stdio.h> #include <string.h> #define sta 1500 #define Num 1600 int main() { in ...

随机推荐

  1. spring:使用会话和请求作用域

    在Web应用中,如果能够实例化在会话和请求范围内共享的bean,那将是非常有价值的事情.例如,在典型的电子商务应用中,可能会有一个bean代表用户的购物车.如果购物车是单例的话,那么将会导致所有的用户 ...

  2. 2016-02-20WebForm登陆验证,判断用户是否登陆 PageBase类

    http://blog.csdn.net/fanbin168/article/details/49404233 很多时候,WebFrom页面,我们需要判断用户是否已经登陆了.假如有很多页面,难道我们要 ...

  3. java多线程学习一

    声明:本篇博客是本人为了自己学习保存的心得,其内容主要是从大神——五月的仓颉的博客中学习而来,在此多谢大神五月的仓颉的分享,敬礼! 第一章:进程和线程的概念 进程:进程是操作系统中作为分配资源的基本单 ...

  4. hdu 3410 单调栈

    http://acm.hdu.edu.cn/showproblem.php?pid=3410 Passing the Message Time Limit: 2000/1000 MS (Java/Ot ...

  5. MongoDB 高可用集群搭建(3.4)

      一.架构概况192.168.56.101192.168.56.102192.168.56.103OS为centos 7.2 架构图: 规划5个组件对应的端口号,由于每台机器均需要同时部署 mong ...

  6. 配合Jenkins自动化构建,bat脚本(一)

    C:\Windows\System32\inetsrv\appcmd.exe stop site ServiceIIS C:\Windows\System32\inetsrv\appcmd.exe s ...

  7. L115

    The reasons of reading books - part I1. You will optimize your brain powerThis shouldn't come as a s ...

  8. python_查找模块的方法

    在python自带的Command Line中: 1. 查找一个模块拥有的方法 import 模块名 help(模块名) or dir(模块名) 2. 查找一个模块拥有的方法 import 模块名 h ...

  9. mysql下this is incompatible with sql_mode=only_full_group_by解决方案

    本地测试没有问题,部署到客户服务器之后报如下错误: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 o ...

  10. jira python操作,自动创建问题

    jira web api地址 http://jira.**.com/plugins/servlet/restbrowser http://jira.**.com/rest/api/2/issue/cr ...