Answer to Question #232081 in Python for kaavya

Question #232081

Sum of Even numbers

Write a program to find the sum of even numbers in first N natural numbers.

Input

The input is an integer N.

Output

The output should be an integer containing the sum of even numbers upto the given number.

Explanation

In the given example

N = 5, the even natural numbers below 5 are 2, 4 Then total = 2 + 4

So, the output should be

6.

Sample Input 1

5

Sample Output 1

6

Sample Input 2

4

Sample Output 2

6




1
Expert's answer
2021-09-02T04:33:58-0400
n = int(input("Enter an integer:   "))
su = 0.0
for i in range(1, n+1):
    if i % 2==0:
        su += i
print(su)
        

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS