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
sumto 0. This will hold the sum of all multiples of 3 and 4. -
Start a loop that goes through each number
ifrom 3 to 150 inclusive. -
Inside the loop, check if
iis divisible by 3 or 4. You can do this by using the modulus operator (%). Ifi % 3 == 0ori % 4 == 0, theniis a multiple of 3 or 4. -
If
iis 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 3's that are needed to write the numbers from 200 to 400.
The sum of all integers from 1 to 520 that are multiples of 4 or 5
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 1000.
Write a program to accept an integer range and print the sum of number that are divisible by either 3 or 5Input Format:An integer range is given inputOutput Format:Print the calculated sum.
2. Devise an algorithm that finds the sum of all the integers in a list
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.