C Program To Calculate BMI and BMI Category

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:

BMI CategoryBMI
Starvation < 15
Anorexic15.1 to 17.5
Underweight17.6 to 18.5
Ideal18.6 to 24.9
Overweight25 to 25.9
Obese30 to 30.9
Morbidly Obese>= 40

Related Read:
else if statement in C
Relational Operators In C
Logical Operators In C

Formula To Calculate Body Mass Index (BMI)

bmi = weight / (height x height);

Logic To Calculate BMI and BMI Category

We ask the user to enter weight in kelogram(kg) and height in meters(m). Then using above formula we calculate BMI(Body Mass Index). Next, by referring to the chart below we display the BMI category.

BMI Category

For BMI Category Ideal:
bmi >= 18.6 && bmi <= 24.9

Expected Output for the Input

User Input:
Enter height in meter
1.4
Enter weight in kg
60

Output:
Your Body Mass Index(BMI) is 30.612246
Your BMI category is: Obese

Video Tutorial: C Program To Calculate BMI and BMI Category


[youtube https://www.youtube.com/watch?v=Lz_o-l5vNwA]

YouTube Link: https://www.youtube.com/watch?v=Lz_o-l5vNwA [Watch the Video In Full Screen.]

Source Code: C Program To Calculate BMI and BMI Category

#include < stdio.h >
int main()
{
    float height, weight, bmi;

    printf("Enter height in meter\n");
    scanf("%f", &height);

    printf("Enter weight in kg\n");
    scanf("%f", &weight);

    bmi = weight / (height * height);

    printf("Your Body Mass Index(BMI) is %f\n", bmi);

    if(bmi < 15)
    {
        printf("Your BMI category is: Starvation\n");
    }
    else if(bmi >= 15.1 && bmi <= 17.5)
    {
        printf("Your BMI category is: Anorexic\n");
    }
    else if(bmi >= 17.6 && bmi <= 18.5)
    {
        printf("Your BMI category is: Underweight\n");
    }
    else if(bmi >= 18.6 && bmi <= 24.9)
    {
        printf("Your BMI category is: Ideal\n");
    }
    else if(bmi >= 25 && bmi <= 25.9)
    {
        printf("Your BMI category is: Overweight\n");
    }
    else if(bmi >= 30 && bmi <= 30.9)
    {
        printf("Your BMI category is: Obese\n");
    }
    else if(bmi >= 40)
    {
        printf("Your BMI category is: Morbidly Obese\n");
    }
    else
    {
        printf("Wrong entry\n");
    }

    return 0;
}

Output 1:
Enter height in meter
0.8
Enter weight in kg
80
Your Body Mass Index(BMI) is 125.000000
Your BMI category is: Morbidly Obese

Output 2:
Enter height in meter
1.4
Enter weight in kg
50
Your Body Mass Index(BMI) is 25.510204
Your BMI category is: Overweight

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Convert Kilometer To Meter, Centimeter, Millimeter: C Program

The distance between two cities (in Kilometer) is input through the keyboard. Write a program to convert and print this distance in meters, centimeter, millimeter.

Note:
1 Kilometer(km) = 1000 Meters(m).
1 Kilometer(km) = 100000 Centimeters(cm).
1 Kilometer(km) = 1000000 Millimeters(mm).

For n Kilometers(KM)
n Kilometer = n * 1000 Meters
n Kilometer = n * 100000 Centimeters
n Kilometer = n * 1000000 Millimeters

Convert Kilometer To Meter, Centimeter, Millimeter: C Program


[youtube https://www.youtube.com/watch?v=zj79Yj0-ctI]

YouTube Link: https://www.youtube.com/watch?v=zj79Yj0-ctI [Watch the Video In Full Screen.]


Source Code: Convert Kilometer To Meter, Centimeter, Millimeter: C Program

#include < stdio.h >

int main()
{
    float km, cm, mm, m;

    printf("Enter distance in Kelometer\n");
    scanf("%f", &km);

    m  = km * 1000.0;
    cm = km * 100000.0;
    mm = km * 1000000.0;

    printf("Distance in Meter is %f\n", m);
    printf("Distance in Centimeter is %f\n", cm);
    printf("Distance in Milimeter is %f\n", mm);

    return 0;
}

Output 1:
Enter distance in Kelometer
10
Distance in Meter is 10000.000000
Distance in Centimeter is 1000000.000000
Distance in Milimeter is 10000000.000000

Output 2:
Enter distance in Kelometer
5
Distance in Meter is 5000.000000
Distance in Centimeter is 500000.000000
Distance in Milimeter is 5000000.000000

PrefixSymbolMultiply by
yottaY1024
zettaZ1021
exaE1018
petaP1015
teraT1012
gigaG109
megaM106
hectokilohk105
myriama104
kilok103
hectoh102
dekada101
UNIT1100
decid10-1
centic10-2
millim10-3
decimillidm10-4
centimillicm10-5
microยต10-6
nanon10-9
picop10-12
femtof10-15
attoa10-18
zeptoz10-21
yoctoy10-24

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert