C Program to accept the height of a person in centimeter & categorize

For a better understanding, we always recommend you to learn the basic topics of C programming listed below:

How to categorize persons related to height?

In this c program, we need to arrange the persons according to their height in centimeters and categorize them as taller, dwarf & average. For that, we need to accept the heights from the user. Check the height of each user using the if conditional statement. If the height is less than 150 cm, we categorize them as short. If the height is between 150 and 165 cm, it is called average height. If the height is between 165 and 195, it falls into the category of taller people.

The logic of this program first declares the variable 'ht' as a float type. Read the height in centimeters from the user and save it into the variable 'ht'. Now check if (ht<150), then we display the height is short. Use else if (ht<150 and ht<=165), then display average height. Otherwise, check else if (ht>=165 and ht<=195), then display taller. Else show abnormal height.

What is the syntax of the if-else statement?

if (testExpression) {

  // codes inside the body of if

} else {

  // codes inside the body of else


If the test expression is true, we execute the code inside the if condition and skip the else part. But if the test expression is false, the reverse is happening; in this program, we have to categorize the persons according to their height. By using the if-else condition, we evaluate the comparison of heights. For more about conditional loops click here


STEP 1: Include the header files to use the built-in header files into the C program.

STEP 2: Declare the variable ht as the float.

STEP 3: Read the Height of the user to ht.

STEP 4: Check if "ht<150" Display the short.

STEP 5: Check using else if "ht>=150" and "ht<=165" then display Average height.

STEP 6: Check else if "ht>=165" and "ht<=195" then display Taller,

else display abnormal height.

C Source Code

                                          #include <stdio.h>

void main() {
  float ht;
  printf("Enter  the Height (in centimeters)\n");
  scanf("%f", & ht);
 /* using if we compare the heights */
  if (ht < 150)
    printf("This person is Short\n");
  else if ((ht >= 150) && (ht <= 165.0))
    printf("This person is Average Height\n");
  else if ((ht >= 165.0) && (ht <= 195.0))
    printf("This person is Taller\n");
    printf("This person is of Abnormal height\n");
} /* End of main() */


Enter  the Height (in centimeters)

This person is Short