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


March 30, 2022, Learn eTutorial
1787

How to categorize persons related to height using C program?

In this C program, we need to arrange the persons according to their height in centimeters and categorize them as Tall, Short & 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 as Short. Use else if (ht<150 and ht<=165), then display Average height. Otherwise, check else if (ht>=165 and ht<=195), then display Tall. Else show abnormal height.

ALGORITHM

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

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 Tall,

STEP 7: Else display abnormal height.


To categorize the person's height, we are using the below C programming topics. please refer these topics for a better understanding

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 Tall\n");
  else
    printf("This person is of Abnormal height\n");
} /* End of main() */
                                      

OUTPUT

Enter  the Height (in centimeters)

145
This person is Short