include <stdio.h>
#include <math.h>
int main()
{
int w, h, b;
float t, a;
printf("Input weight, height:\n");
scanf("%d,%d", &w, &h);
a = h / 100.0;
b = w * 2;
t = (float)w / (a * a);
printf("weight=%d\n", b);
printf("height=%.2f\n", a);
printf("t=%.2f\n", t);
return 0;
}
第二部分代码的这一句:
t =(float)weight/(float)(height*height/10000);
height是整数,因此(height*height / 10000)会作为整数来计算,然后对结果取整。改一下就一样了:
t =(float)weight/((float)(height*height)/10000);
```c++