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.
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
n = int(input("Enter an integer:Â Â "))
su = 0.0
for i in range(1, n+1):
  if i % 2==0:
    su += i
print(su)
    Â
Comments
Leave a comment