The C Programming Language,C程序设计语言 (K&R),为C语言的设计者Dennis M. Ritchie和著名的计算机科学家Brian W.Kernighan合著的 一本介绍C语言的权威经典著作,学习c语言至今,第一次读这本书,这本书适合有一定的c语言基础的深入学习。
为什么说不适合初学者,觉得这本书更像一本字典,比如在函数章节,举例代码中用到了下面章节的数组,用到了数据结构的栈知识,为了学习大师的代码,在读这本书的时候,书中引用的代码,一一记录如下
1、华氏温度与摄氏温度对照表
#include
/* 当 fahr=0,20,… ,300 时,分别
打印华氏温度与摄氏温度对照表 */
int main()
{
int fahr, celsius;
int lower, upper, step;
lower = 0; /* 温度表的下限 */
upper = 300; /* 温度表的上限 */
step = 20; /* 步长 */
fahr = lower;
while (fahr <= upper) {
celsius = 5 * (fahr-32) / 9;
printf("%d\t%d\n", fahr, celsius);
fahr = fahr + step;
}
return 0;
}
View Code
#include
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300; floating-point version */
int main()
{
float fahr, celsius;
float lower, upper, step;
lower = 0; /* lower limit of temperatuire scale */
upper = 300; /* upper limit */
step = 20; /* step size */
fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
return 0;
}
View Code
#include
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300; floating-point version */
int main()
{
int fahr;
for (fahr = 0; fahr <= 300; fahr = fahr + 20)
printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
return 0;
}
View Code
来源:https://www.cnblogs.com/GoldenEllipsis/p/13379462.html