案例1
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# more hello.c
#include <stdio.h>
int main()
{
printf("hello, world\n");
return 0;
}
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# cc hello.c -o hello.out
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# ls *.out
hello.out tem2.out
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# ./hello.out
hello, world
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec#
源文件(.c),编译(cc),执行(.out)当前目录下(./)
案例2
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# more temperature.c
#include <stdio.h>
/*当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;
}
}
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec#
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# cc temperature.c -o tem.out
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# ./tem.out
0 -17
20 -6
40 4
60 15
80 26
100 37
120 48
140 60
160 71
180 82
200 93
220 104
240 115
260 126
280 137
300 148
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec#
案例3
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# more temperature1.c
#include <stdio.h>
/*当fahr=0,20,……,300时,分别打印华氏温度与摄氏温度对照表*/
int main()
{
float fahr, celsius;
float lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
while (fahr <= upper){
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec#
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# cc temperature1.c -o tem1.out
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# ./tem1.out
0 -17.8
20 -6.7
40 4.4
60 15.6
80 26.7
100 37.8
120 48.9
140 60.0
160 71.1
180 82.2
200 93.3
220 104.4
240 115.6
260 126.7
280 137.8
300 148.9
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec#
案例4
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# more temperature2.c
#include <stdio.h>
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;
}
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec#
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# cc temperature2.c -o tem2.out
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec# ./tem2.out
0 -17.8
20 -6.7
40 4.4
60 15.6
80 26.7
100 37.8
120 48.9
140 60.0
160 71.1
180 82.2
200 93.3
220 104.4
240 115.6
260 126.7
280 137.8
300 148.9
root@iZuf6evbev3w2mqyyrgfcqZ:~/codec#
66万+

被折叠的 条评论
为什么被折叠?



