单位换算求解c++。

【问题描述】

已知1英寸=25.4毫米,请你写一个方便的小工具,将输入的英寸数(大于0)换算成厘米数。

输入:要转换的英寸数(大于0)

输出:转换后的厘米数(保留两位小数)

要求:使用scanf与printf

【样例输入】

11.1

【样例输出】

28.19


#include <iostream>
int main()
{
    float inch;
    scanf("%f",&inch);
    printf("%.2f",inch*2.54);
}
#include <stdio.h>

double inch_to_cm(double x)
{
    return x * 2.54;
}

int main()
{
    double x;
    scanf("%lf", &x);
    printf("%.2lf", inch_to_cm(x));
    return 0;
}