qq_半宅患者_0
2016-10-27 13:42
#include <stdio.h> float count(int x, int t) { float cost = 2.3; if(t >= 23 || t <5 ) { cost = 2.3 * 1.2; } printf("cost= %f \n", cost); if(x <= 3) { return 13 + 1; }else { return 13 + (x-3) * cost + 1; } } int main() { printf("%f \n", count(12, 8)); printf("%f \n", count(12, 6)); printf("%f",(13 + (12-3) * 2.3 + 1)); return 0; }
cost= 2.300000
34.699997
cost= 2.300000
34.699997
34.700000
printf("%f \n", count(12, 8));
printf("%f \n", count(12, 6));
printf("%f",(13 + (12-3) * 2.3 + 1));
//这些输出语句都在f前加上.2就会只输出两位小数,即
printf("%.2f \n", count(12, 8));
printf("%.2f \n", count(12, 6));
printf("%.2f",(13 + (12-3) * 2.3 + 1));
C语言中,输出double类型(双精度实型)以及float类型(单精度实型)时,默认输出6位小数哒
C语言入门
926025 学习 · 20793 问题
相似问题