用c进行度量之间的换算

img

厘米先转换成米,然后除以0.3048,得到的就是英尺数,其中整数部分为foot,小数部分乘以12后,其整数部分为inch

米(meter)= 英尺*0.3048 = 100厘米(centimetre)= (foot+inch/12)×0.3048
英尺(foot)= 厘米/30.48 ,让输入的厘米除以30.48,便是带小数的英尺,直接取整便是所得英尺。将小数部分乘以12并取整,便为英寸。

#include <stdio.h>
int main()
{ 
    int cm=0;
    scanf("%d",&cm);    //输入的cm
    int foot = cm/30.48;  /* 1英尺等于30.48厘米 */
    int inch = (cm/30.48 - foot) * 12;
    printf("%d %d",foot,inch);
    return 0;
}