最近闲的有点无聊,打算重新夯实一下C语言基础,顺便做一做K&R的课后习题
1-1、自己试试
1-2、printf(“\c”)的时候,只剩一个c了,那么这是为什么呢?
c语言前定义了一些+字母表示平常不能显示的ASCII字符,除了特定的几个字母以外,其他的就只能表示字母本身啦
1-3、程序开头增加一行printf();即可
1-4、很简单,找到摄氏如何转华氏公式转换一下就行
#include "stdio.h"
main()
{
float fahr, celsius;
float lower, upper, step;
printf("Temple Change List\n");
printf("\n");
lower = 0; /* lower limit of temperatuire scale */
upper = 300; /* upper limit */
step = 20; /* step size */
celsius = lower;
while (celsius <= upper) {
fahr = celsius * 1.8 + 32;
printf("%3.0f %6.1f\n",celsius, fahr);
celsius = celsius + step;
}
}
1-5、输出代码如下
#include "stdio.h"
main()
{
float fahr, celsius;
float lower, upper, step;
printf("Temple Change List\n");
printf("\n");
lower = 0; /* lower limit of temperatuire scale */
upper = 300; /* upper limit */
step = 20; /* step size */
celsius = upper;
while (celsius >= lower) {
fahr = celsius * 1.8 + 32;
printf("%3.0f %6.1f\n",celsius, fahr);
celsius -= step;
}
}