题目:
医务工作者经广泛的调查和统计,给出了以下公式:
若体指数为t,体重为w,身高为h,有:
t=w/
当t<18时,为低体重
当18<=t<25时,为正常体重
当25<=t<27时,为超重体重
当t>=27时,为肥胖
请从键盘输入你的身高h和体重w,根据给定的公式,计算你的体指数,判断出是什么类型
要点:
(1)选择结构if类与switch类的选择
(2)逻辑判断条件的书写
(3)数学函数的调用
解决:
#include <stdio.h>
#include <math.h>
int main()
{
float t=0,w=0,h=0;
printf("please input your weight(kg)\n");
scanf("%f",&w);
printf("please input your height(m)\n");
scanf("%f",&h);
t=w/pow(h,2);
if(t<18)
{
printf("your weight is low!");
}
else if(t>=18&&t<25)
{
printf("your weight is normal!");
}
else if(t>=25&&t<27)
{
printf("your weight is high!");
}
else
{
printf("your weight is too high!");
}
}