82.8k views
4 votes
Write a loop to print all the double-digit multiples of 5?

1 Answer

6 votes

Final answer:

To print all the double-digit multiples of 5, use a loop that starts at 10 and increments by 5 while checking that numbers are less than 100. Each iteration prints a multiple of 5 without needing a condition since the increment ensures multiples of 5 are printed.

Step-by-step explanation:

To write a loop to print all the double-digit multiples of 5, you can use a for or while loop. The double-digit numbers range from 10 to 99. Since we are looking for multiples of 5, we will start at the lowest double-digit multiple of 5, which is 10, and continue up to and including the largest double-digit multiple of 5, which is 95. Here's how you might write this loop in a pseudocode-style format:

for (int i = 10; i < 100; i += 5) {
if (i % 5 == 0) {
print(i);
}
}

In this loop, we initialize a counter variable i to 10, then continue to increment i by 5 on each iteration, since we are interested in counting by multiples of 5. The condition i % 5 == 0 ensures that we are only printing numbers that are truly multiples of 5, although this conditional check is redundant because we are incrementing by 5. Thus, each iteration of the loop will print a double-digit multiple of 5, ending with the number 95.

User ChviLadislav
by
7.7k points

No related questions found