Write a program in pseudo code to categorize a person’s BMI (Body Mass Index) as Underweight (<18.5), Normal (18.5-24.9), or Overweight (≥25).
Write a switch/case pseudo code to display a message based on a day number (1=Monday, 2=Tuesday, …, 7=Sunday).
What is the difference between a while loop and a do-while loop?
Optimize a loop to calculate the factorial of a number.
Write pseudo code to sum digits of a number until a single digit is obtained.
Answers and Descriptions
Answer:
1 2 3 4 5 6 7 8 | INPUT bmi IF bmi < 18.5 THEN OUTPUT "Underweight" ELSE IF bmi < 25 THEN OUTPUT "Normal" ELSE OUTPUT "Overweight" ENDIF |
Description: Nested If-Else statements handle multiple BMI ranges, testing complex selection logic for real-world applications.
Answer:
1 2 3 4 5 6 7 8 9 10 11 | INPUT day SWITCH day CASE 1: OUTPUT "Monday" CASE 2: OUTPUT "Tuesday" CASE 3: OUTPUT "Wednesday" CASE 4: OUTPUT "Thursday" CASE 5: OUTPUT "Friday" CASE 6: OUTPUT "Saturday" CASE 7: OUTPUT "Sunday" DEFAULT: OUTPUT "Invalid day" ENDSWITCH |
Description: Switch/case maps a single variable to multiple outcomes, ideal for enumerated values like days, enhancing code clarity.
Answer: A while loop checks the condition before executing, while a do-while loop executes at least once before checking the condition.
Description: While loops may skip execution if the condition is false, whereas do-while loops guarantee one execution, useful for menu-driven programs.Answer:
1 2 3 4 5 6 | INPUT n factorial = 1 FOR i = 1 TO n factorial = factorial * i ENDFOR OUTPUT factorial |
Description: This loop uses a single variable to accumulate the product, demonstrating efficient iteration for factorial computation.
Answer:
1 2 3 4 5 6 7 8 9 10 | INPUT number WHILE number > 9 sum = 0 WHILE number > 0 sum = sum + (number MOD 10) number = number DIV 10 ENDWHILE number = sum ENDWHILE OUTPUT number |
Description: This while loop handles unknown iterations, summing digits until a single digit remains, testing advanced iteration logic.