Answer to Question #232082 in Python for kaavya

Question #232082

Sum of Odd Numbers

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

Input

The input is an integer N.

Output

The output should be an integer containing the sum of odd numbers up to the given number.

Explanation

In the given example sum of odd numbers less than

N = 10 are total = 1 + 3 + 5 + 7 + 9

So, the output should be

25.

Sample Input 1

10

Sample Output 1

25

Sample Input 2

5

Sample Output 2

9




1
Expert's answer
2021-09-03T01:41:28-0400
N= int(input())
sumResult=0
for i in range(1,N+1):
    if i %2 !=0:
        sumResult+=i
print(sumResult)
        




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