School ICT Self Study

Selection and Iteration Structures

35 viewsG11-01. Programming
0

  1. 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).

  2. Write a switch/case pseudo code to display a message based on a day number (1=Monday, 2=Tuesday, …, 7=Sunday).

  3. What is the difference between a while loop and a do-while loop?

  4. Optimize a loop to calculate the factorial of a number.

  5. Write pseudo code to sum digits of a number until a single digit is obtained.

Spread the love
Ruwan Suraweera Changed status to publish 4 days ago
0

Answers and Descriptions

  1. Answer:

Description: Nested If-Else statements handle multiple BMI ranges, testing complex selection logic for real-world applications.

  1. Answer:

Description: Switch/case maps a single variable to multiple outcomes, ideal for enumerated values like days, enhancing code clarity.

  1. 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.

  2. Answer:

Description: This loop uses a single variable to accumulate the product, demonstrating efficient iteration for factorial computation.

  1. Answer:

Description: This while loop handles unknown iterations, summing digits until a single digit remains, testing advanced iteration logic.

Spread the love
Ruwan Suraweera Changed status to publish 4 days ago
Write your answer.