234k views
2 votes
Find the summation of even number between (2,n)​

User Risel
by
5.4k points

1 Answer

6 votes

Answer:

The program in python is as follows:

n = int(input("n: "))

sum = 0

for i in range(2,n+1):

if i%2 == 0:

sum+=i

print(sum)

Step-by-step explanation:

This gets input n

n = int(input("n: "))

This initializes sum to 0

sum = 0

This iterates through n

for i in range(2,n+1):

This checks if current digit is even

if i%2 == 0:

If yes, take the sum of the digit

sum+=i

Print the calculated even sum

print(sum)

User Wsbaser
by
5.3k points