C program to read the height of a person and the print person is taller, dwarf, or average height person

Here, we are going to learn how to read the height of a person and the print person is taller, dwarf, or average height person using C program?
Submitted by Nidhi, on August 27, 2021

Problem statement

Here, we will create a double variable height and read its value from the user and print the person is taller, dwarf, or average height person.

Program

The source code to read the height of the person and the print person is taller, dwarf or average height person is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to read the height of the person,
// and print person is taller, dwarf, or
// average height person

#include <stdio.h>

int main()
{
    double height = 0;

    printf("Enter Height (in centimetres): ");
    scanf("%lf", &height);

    if ((height >= 150.0) && (height <= 170.0)) {
        printf("Person is average height person");
    }
    else if ((height > 170.0) && (height <= 195.0)) {
        printf("Person is taller");
    }
    else if (height < 150.0) {
        printf("Person is dwarf");
    }
    else
        printf("Abnormal height \n");

    return 0;
}

Output

RUN 1:
Enter Height (in centimetres): 172
Person is taller

RUN 2:
Enter Height (in centimetres): 147
Person is dwarf

Explanation

Here, we created a variable height of double type, and read the value of the height variable in centimeters. After that, we checked the value of height and the print person is taller, dwarf, or average height person on the screen.

C Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.