Q: The Body Mass Index (BMI) is defined as ratio of the weight of a person (in kilograms) to the square of the height (in meters). Write a c program that receives weight and height, calculates the BMI, and reports the BMI category as per the following table:





#include<stdio.h>
#include<math.h>  /*this header file is used to include all predefined maths function*/

int main()
{

    /*Weight should be in Kilograms*/
    /*Height should be in Meters*/
    float weight, height, BMI;
   
    printf("Enter the weight of person: ");
    scanf("%f", &weight);

    printf("Enter the height of person: ");
    scanf("%f", &height);

    /*BMI stands for Body Mass Index*/
    BMI = weight/(pow(height, 2));    /*pow is a function that gives second value peresent in bracket is as power of first value of bracket*/

    printf("\n\nThe BMI of person is: %f\n", BMI);

    if (BMI>0 && BMI<=15)
        printf("BMI Category is Starvation");

    else if (BMI>=15.1 && BMI<=17.5)
        printf("BMI Category is Anorexic");

    else if (BMI>17.6 && BMI<=18.5)
        printf("BMI Category is Underweight");

    else if (BMI>18.6 && BMI<=24.9)
        printf("BMI Category is Ideal");

    else if (BMI>25 && BMI<=25.9)
        printf("BMI Category is Overweight");

    else if (BMI>30 && BMI<=30.9)
        printf("BMI Category is Obese");

    else if (BMI>=40)
        printf("BMI Category is Morbidly Obese");

return 0;
   
}

-----------------------------------------
Output:


Enter the weight of person: 60
Enter the height of person: 1.6


The BMI of person is: 23.437500
BMI Category is Ideal

Comments

Popular posts from this blog

Q: The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate area & perimeter of the rectangle and area & circumference of the circle.

Q: If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulus operator ‘%’)