C Program to Accept the Height of a Person & Categorize as Taller, Dwarf & Average

«
»

This C program accepts the height of a person & categorize as taller, dwarf & average.

Problem Description

This program accepts the height of a person as input and categorizes as taller, dwarf & average.

Problem Solution

1. Take the height of a person as input.
2. Using if,else statements, categorize it as taller, dwarf & average and print the output accordingly.
3. Exit.

advertisement
Program/Source Code

Here is source code of the C program to accept the height of a person & categorize as taller, dwarf & average. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C program to accept the height of a person in centimeter and
  3.  * categorize the person based on height as taller, dwarf and
  4.  * average height person
  5.  */
  6.  
  7. #include <stdio.h>
  8. void main()
  9. {
  10.     float height;
  11.  
  12.     printf("Enter  the Height (in centimetres) \n");
  13.     scanf("%f", &height);
  14.     if (height < 150.0)
  15.         printf("Dwarf \n");
  16.     else if ((height >= 150.0) && (height <= 165.0))
  17.         printf(" Average Height \n");
  18.     else if ((height > 165.0) && (height <= 195.0))
  19.         printf("Taller \n");
  20.     else
  21.         printf("Abnormal height \n");
  22. }
Program Explanation

1. Take the height of a person as input and store it in the variable height.
2. If the variable height is lesser than 150 cm, then print the output as “Dwarf”.
3. If the variable height is lesser than or equal to 165 cm and greater than or equal to 150 cm, then print the output as “Average Height”.
4. If the variable height is lesser than or equal to 195 cm and greater than 165 cm, then print the output as “Taller”.
5. Exit.

advertisement
Runtime Test Cases
Enter  the Height (in centimetres)
165
Average Height
 
Enter  the Height (in centimetres)
140
Dwarf
 
Enter  the Height (in centimetres)
190
Taller

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

advertisement
If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics of C, go to C Programming Examples.

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn