Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
C program to read the grade of student print equiv... >>
<< C program to perform the ATM Transactions...