(foot+inch/12)*0.3048 = cm / 100
foot+inch/12 = cm / (100 * 0.3048) = cm / 30.48
因为1foot = 12inch,所以inch / 12 <1,所以foot = cm/30.48的整数部分 inch / 12 = cm/30.48的小数部分。
六七行就是完成这个功能。
扩展资料:一、英尺和英寸的知识
1、1码 = 3英寸 ,1英尺 = 12 英寸;
2、码英文字母是 yard
3、英尺英文字母是 foot( 单数 ) feet( 复数 )
4、英寸英文单词是 inch ( 单数 )inches( 复数 )
二、长度单位转换
#include<stdio.h>
#define Mile_to_meter 1609 //1英里 = 1690米
#define Foot_to_centimeter 30.48 //1英里 = 1690米
#define Inch_to_centimeter 2.54 //1英里 = 1690米
int main(){
float mile, foot, inch
scanf("%f%f%f", &mile, &foot, &inch)
printf("%fmiles = %f meters\n", mile, mile * Mile_to_meter)
printf("%ffeet = %f centimeters\n", foot, foot * Foot_to_centimeter )
printf("%finches = %f centimeters\n", inch, inch * Inch_to_centimeter )
return 0
}
#includevoid
main()
{
float
ych,yc,lm
printf("本程序将完成英尺和英寸转换为厘米\n")
printf("请输入英尺数目:")
scanf("%f",&ych)
printf("请输入英寸数目:")
scanf("%f",&yc)
lm=ych*30.48+yc*2.54
printf("\n%.0f英尺%.0f英寸折合为:%.2f厘米",ych,yc,lm)
}
请采纳答案,支持我一下。