编写一个函数,将n 厘米转换为x英尺y英寸,结果保存在局部变量中,再编写一个函数,将x英尺y英寸转换为n厘米,最后编程验证函数的正确性(一英尺等于十二英寸,一英寸等于2.54厘米)
1条回答 默认 最新
threenewbee 2018-11-25 12:53关注如果问题解决,请点我回答左上角的采纳。
#include "stdafx.h" #include "stdio.h" float cm2inch(float cm) { return cm / 2.54; } float getinchfromft(float ft) { return (ft / 12.0 - int(ft / 12.0)) * 12; } float ftinch2cm(int ft, int ih) { return (ft * 12 + ih) * 2.54; } int main() { printf("1ft2inch=%fcm\n", ftinch2cm(1, 2)); printf("33.02cm=%dft%finch\n", int(cm2inch(35.56)) / 12, getinchfromft(cm2inch(35.56))); return 0; }1ft2inch=35.560001cm
33.02cm=1ft2.000001inch
Press any key to continue . . .本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报