#include <stdio.h>
main()
{
printf("hello,world\n")
}
#include <stdio.h>
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("3%d\t6%d\n,fahr,celsius);
fahr=fahr+step;
}
}
#include <stdio.h>
main()
{
float fahr,clesius;
int lower, upper, step;
lower=20;
upper=300;
step=20;
fahr=lower;
while(fahr<=upper){
celsius=(5.0/9.0)*(fahr-32);
printf("3%.0f6%.1f\n",fahr,celsius);
fahr=fahr+step;
}
}
练习,1-1,1-2,1-3不会
练习 1-4
#include <stdio.h>
main()
{
float fahr,clesius;
int lower, upper, step;
lower=20;
upper=300;
step=20;
fahr=upper;
while(fahr>=lower){
celsius=(5.0/9.0)*(fahr-32);
printf("3%.0f6%.1f\n",fahr,celsius);
fahr=fahr-step;
}
}
练习1-5,for 语句倒序温度转换
#include <stdio.h>
main()
{
int fahr;
for (fahr=0;fahr<=300;fahr=fahr+20)
printf("%3d%6.1f\n",fahr,(5.0/9.0)*(fahr-32));
}
#include <stdio.h>
main()
{
int fahr;
for (fahr=300;fahr>=0;fahr=fahr-20)
printf("%3d%6.1f\n",fahr,(5.0/9.0)*(fahr-32));
}
1.4 符号常量
用#define 把符号常量定义为一个特定的字符串【相当于给数据起个代号?】
#define 在main()的上面,句末没有【;】
#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));
}
1.5 字符输入/输出