Skip to content
Solved Examples · Example 25

Q.Write a C program to accept the height of a person and determine whether he is a dwarf, average man, taller or if he possess an abnormal height. The textbook presents this worked program, transcribed exactly as printed (including its printed errors):
#include<stdio.h>  
void main()  
{  
float ht;  
printf("Enter the height (in centimeters)\n");  
scanf("%f, &ht);  
if (ht<130.0)  
    printf("Dwarf\n");  
else if ((ht>=130.0)&&(ht<=155.0))  
    printf("Average height\n");  
else if ((ht>=150.0)&&(ht<=185.0))  
    printf("Taller\n");  
else  
    printf("Abnormal height\n");  
}  
/*End of main()*/  
Sample output printed in the textbook:
Enter the height  
154.0  
Average height  

Karnataka PUCTextbookLongImportance★★★★★est
75% · 116/154 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

[!TLDR]

An if / else-if ladder sorts the height into Dwarf / Average / Taller / Abnormal; 154.0 cm is Average height.

An else-if ladder tests a series of ranges in order and runs the first branch whose condition is true, skipping the rest. Because the tests are checked in sequence, each later branch only needs its own upper bound (the lower bound is guaranteed by the earlier branches that already failed) - this keeps the bands from overlapping and reads more clearly than repeating both limits. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.