Write an algorithm (pseudocode) that uses iteration to find the sum of all multiples of 3 and all multiples of 4 between 3 and 150 inclusive. Print the sum.
Question
Write an algorithm (pseudocode) that uses iteration to find the sum of all multiples of 3 and all multiples of 4 between 3 and 150 inclusive. Print the sum.
Solution
Sure, here is the pseudocode for the problem:
Initialize sum to 0
For each number i from 3 to 150
If i is divisible by 3 or i is divisible by 4
Add i to sum
End For
Print sum
Here is the detailed step-by-step explanation:
-
Initialize a variable
sum
to 0. This will hold the sum of all multiples of 3 and 4. -
Start a loop that goes through each number
i
from 3 to 150 inclusive. -
Inside the loop, check if
i
is divisible by 3 or 4. You can do this by using the modulus operator (%
). Ifi % 3 == 0
ori % 4 == 0
, theni
is a multiple of 3 or 4. -
If
i
is a multiple of 3 or 4, add it tosum
. -
After the loop ends, print the value of
sum
. This is the sum of all multiples of 3 and 4 between 3 and 150 inclusive.
Similar Questions
Find the sum of all four-digit numbers that can be made using thedigits 1, 2, 3 and 4 without restriction.
The sum of all natural numbers between 100 and 200, which are multiples of 3 isa.4950b.4900c.5000d.4980
The sum of all integers from 1 to 520 that are multiples of 4 or 5?ans.20842118752This Questi
What will be the output of the following code?i = 3for i in range (4) print (i)
How many of the first n natural numbers must be added to produce a sum of 4,950.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.