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.
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
N= int(input())
sumResult=0
for i in range(1,N+1):
  if i %2 !=0:
    sumResult+=i
print(sumResult)
    Â
Comments
Leave a comment