177k views
1 vote
Write programs with loops that compute: a. The sum of all even numbers between 2 and 100 (inclusive).

User Miro Hudak
by
4.7k points

2 Answers

6 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 Rushank Shah
by
4.5k points
3 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 Adam Westbrook
by
4.1k points