C语言笔记1

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();
}
 

 

 

 

 

 

 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值