95.9k views
13 votes
Write a pseudo code to print sum of all even numbers from 1 to 100

1 Answer

5 votes

(python) Answer:

sum = 0

for i in range 1 to 101:

if i modulo 2 == 0:

sum += i

print(sum)

Step-by-step explanation:

first we declare the sum variable

then go through all numbers 1 through 100 (range 1 to 101 because python range does not include the last number - if we did 1 to 100 it would look at 1 to 99)

if the number is even (divide by 2, check if there's a remainder, if not it's even and we will add the number to the sum

finally print the sum

User Michael Prewecki
by
8.5k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.