C语言学习笔记1
时间:2010-07-17 来源:xmg
HelloWorld
#include <stdio.h>
main()
{
printf("Hello World\n");
getch();
}
FahrShiftCelsius1.0
#include <stdio.h>
/* 当fahr= 0,20,...,300时,分别
打印华氏温度 - 摄氏温度对照表 */
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;
}
getch();
}
FahrShiftCelsius2.0
#include <stdio.h>
/* 当fahr= 0,20,...,300时,分别
打印华氏温度 - 摄氏温度对照表
浮点数版本*/
main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0; /* 温度表的下限 */
upper = 300; /* 温度表的上限 */
step = 20; /* 步长 */
fahr = lower;
while (fahr <= upper){
celsius = (5.0 / 9.0) * (fahr - 32);
printf("%3.0f\t%6.1f\n", fahr, celsius);
fahr = fahr + step;
}
getch();
}
CelsiusShiftFahr
#include <stdio.h>
/* 打印摄氏温度 - 华氏温度*/
main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0; /* 温度表的下限 */
upper = 300; /* 温度表的上限 */
step = 20; /* 步长 */
celsius = lower;
while (celsius <= upper){
fahr = (9.0 / 5.0) * celsius + 32;
printf("%3.0f\t%6.0f\n", celsius, fahr);
celsius = celsius + step;
}
getch();
}
FahrShiftCelsius3.0
#include <stdio.h>
/* 打印华氏温度-摄氏温度 for版*/
main()
{
int fahr;
for (fahr = 0; fahr <= 300; fahr = fahr + 20){
printf("%3d %6.1f\n", fahr, (5.0/9.0) * (fahr-32));
}
getch();
}
FahrShiftCelsius4.0
#include <stdio.h>
/* 打印华氏温度-摄氏温度 for逆序版*/
main()
{
int fahr;
for (fahr = 300; fahr >= 0; fahr = fahr - 20){
printf("%3d %6.1f\n", fahr, (5.0/9.0) * (fahr-32));
}
getch();
}
FahrShiftCelsius5.0
#include <stdio.h>
#define LOWER 0 /* 表的下限 */
#define UPPER 300 /* 表的上限 */
#define STEP 20 /* 步长 */
/* 打印华氏温度-摄氏温度*/
main()
{
int fahr;
for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP){
printf("%3d %6.1f\n", fahr, (5.0/9.0) * (fahr-32));
}
getch();
}
相关阅读 更多 +










