Write the pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25).
To print all multiples of 5 between 10 and 25, we use the concept of iteration or loop. We start by initializing a variable with the first multiple, which is 10. The algorithm then repeatedly checks if the number is within the range (less than or equal to 25). If it is, the number is printed, and then 5 is added to it to get the next multiple.
The pseudocode uses a WHILE loop structure similar to Example 4.8 in the text. This ensures the statements are executed repeatedly as long as the specified condition remains true.
Pseudocode: Step 1: SET num = 10 Step 2: WHILE num <= 25, REPEAT steps 3 and 4 Step 3: PRINT num Step 4: SET num = num + 5
In this algorithm, Step 1 sets the starting value. Step 2 checks the condition for the loop to continue. Steps 3 and 4 perform the printing and increment. Once num exceeds 25, the loop terminates, having printed 10, 15, 20, and 25.
Explanation
The answer is derived from the structure shown in Example 4.8 of the provided context, which demonstrates how to write pseudocode using a WHILE loop for repetition. The logic initializes a variable at the lower bound (10) and increments it by the step value (5) until the upper bound (25) is crossed. This aligns with the textbook's definition of a loop as execution of statements repeatedly till a condition is satisfied.
Solution Steps
Step 1: Initialize the variable 'num' to the starting value 10.
Step 2: Define the loop condition 'WHILE num <= 25' to ensure the range includes both 10 and 25.
Step 3: Inside the loop, print the current value of 'num'.
Step 4: Increment 'num' by 5 to move to the next multiple.
Step 5: Terminate the loop once the condition (num <= 25) becomes false.