在C语言使用函数调用形式计算单位的换算。

Python013

在C语言使用函数调用形式计算单位的换算。,第1张

#include <stdio.h>

void main()

{

float inch

printf("请输入您的高度(英尺)\n")

scanf("%f", &inch)

printf("%f 英尺等于 %f 英寸\n", inch, inch * 12.0)

printf("%f 英尺等于 %f 厘米\n", inch, inch * 12.0 * 2.54)

printf("%f 英尺等于 %f 米\n", inch, inch * 12.0 * 2.54/100.0)

}

基本的功能, 输入异常之类的判定没有加

#include <stdio.h>

#define METER_TO_CM     ((float)100)

#define FOOT_TO_METER   ((float)0.3048)

#define FOOT_TO_INCH    (12)

int main()

{

    float centimetre

    float temp

    int foot = 0

    int inch = 0

    printf("Please input the value(cm):\n")

    scanf("%f", &centimetre)

    

    temp = centimetre / METER_TO_CM / FOOT_TO_METER //计算英尺值(包含小数)

    //转换为相应的英尺和英寸

    foot = (int)temp

    inch = (temp - foot) * FOOT_TO_INCH

    printf("%d %d\n", foot, inch)

    return 0

}