C语言基础学习

案例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# 
 


 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值