20,284 views
2 votes
2 votes
Write programs with loops that compute: a. The sum of all even numbers between 2 and 100 (inclusive).

User Leftium
by
2.5k points

2 Answers

9 votes
9 votes

Step-by-step explanation:

a:

sum = 0

for i in range(0, 101):

if i%2 == 0:

sum = sum + i

alternatively you could do for i in range(0, 101, 2) and leave out the i%2 line

b:

sum = 0

for i in range(0, 101):

sum = sum + i*i

c:

value = 2

while value <= 220:

if value > 20:

sum = sum + value

value = value * 2

d:

a = int(input("Input a"))

b = int(input("Input b"))

sum = 0

for i in range(a, b+1):

sum = sum + i

e:

word = input("Input a number")

sum = 0

for letter in word:

if isdigit(letter):

sum = sum + int(letter)

I'm sure this is past due, but feel free to reach out if you have any other questions :)

User Midinastasurazz
by
2.3k points
13 votes
13 votes

A basic vb.net program screenshot is attached.

Hope this helps!

Write programs with loops that compute: a. The sum of all even numbers between 2 and-example-1
User Damote
by
2.6k points