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:
INPUT bmi
IF bmi < 18.5 THEN
OUTPUT "Underweight"
ELSE IF bmi < 25 THEN
OUTPUT "Normal"
ELSE
OUTPUT "Overweight"
ENDIFDescription: Nested If-Else statements handle multiple BMI ranges, testing complex selection logic for real-world applications.
Answer:
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"
ENDSWITCHDescription: 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:
INPUT n
factorial = 1
FOR i = 1 TO n
factorial = factorial * i
ENDFOR
OUTPUT factorialDescription: This loop uses a single variable to accumulate the product, demonstrating efficient iteration for factorial computation.
Answer:
INPUT number
WHILE number > 9
sum = 0
WHILE number > 0
sum = sum + (number MOD 10)
number = number DIV 10
ENDWHILE
number = sum
ENDWHILE
OUTPUT numberDescription: This while loop handles unknown iterations, summing digits until a single digit remains, testing advanced iteration logic.