Body Mass Index

We can measure our body fat by using Body Mass Index (BMI) value.

BMI = weight / (height * height)


Where,

Weight in kilograms,

height in meter.

Example:

Weight = 60 kg

Height = 1.7 m

BMI = 60 / (1.7 * 1.7)

BMI = 20.76




Types

Based on the BMI value, we can categorize people into four following types

Under weight - BMI < 18.5 (less than 18.5)

Normal weight - 18.5 >= BMI <= 25 (greater than or equal to 18.5 and less than or equal to 25)

Over weight - 25 > BMI <= 30 (greater than 25 and less than or equal to 30)

Obese - BMI > 30 (greater than 30)




Let's write a BMI calculator using C

The program will get weight and height from user and tell which type they belong based on the BMI value.


Example

/*
 * Body Mass Index calculator *
 * Language : C               *
 */
 
#include<stdio.h>

int main()
{
    float weight,height,BMI;
    
    printf("Enter your weight(kg) and height(meter)\n");
    scanf("%f%f",&weight,&height);
    
    BMI = weight / (height * height);
    
    printf("Your BMI = %f\n",BMI);

    // less than 18.5
    if(BMI < 18.5)                    
           printf("Under weight\n");
    // greater than or equal to 18.5 and less than or equal to 25 
    else if(BMI >= 18.5 && BMI <= 25)  
           printf("Normal weight\n"); 
    // greater than 25 and less than or equal to 30
    else if(BMI > 25 && BMI <= 30)   
           printf("Over weight\n");
    // greater than 30
    else                           
           printf("Obese\n");
           
    return 0;
}