C语言 体型预测

条件:体指数 = w(体重) / h (身高)^2

           t < 18 低体重;

          18 <= t <   25; 正常体重;

          25 <= t <   27; 超重体重;

          t    >=  27      ; 肥胖;

#include <stdio.h>
void main()
{
    float w,h,t;

    printf("请输入你的体重和身高,用空格分隔开。\n");

    scanf("%lf %lf",&w,&h);

    t = w/(h*h) ;

    if( t < 18)
    {
        printf("低\n");
    }
    else if( t >= 18 && t < 28)
    {
        printf("正常\n");
    }
    else if( 25 <= t < 27)
    {
        printf("为超重体重\n");
    }
    else if( t >= 27)
    {
        printf("肥胖\n");
    }

}

总结:

考   if - if else 的 知识点。

该结构为先判断 if 中条件是否成立。成立则不执行else

不成立,则判断if else 若 if else 成立,则不继续判断 if else 

猜你喜欢

转载自blog.csdn.net/qq_26974599/article/details/81264487