Problem Description
Write a program to find the sum of odd numbers, even numbers and negative numbers
Input:Positive and negative numbers
Output:Display Sum of ODD,EVEN and NEGATIVE numbers respectively.
Refer sample input and output for formatting specificationCODING ARENA
n=int(input())
b=[]
for i in range(0,n):
a=int(input())
b.append(a)
sum1=0
sum2=0
sum3=0
for j in b:
if(j>0):
if(j%2==0):
sum1=sum1+j
else:
sum2=sum2+j
else:
sum3=sum3+j
print("Sum of positive even numbers:",sum1)
print("Sum of positive odd numbers:",sum2)
print("Sum of negative numbers:",sum3)
Test Case 1
Input (stdin)10 2 3 4 5 6 7 8 9 10 11
Expected OutputSum of positive even numbers: 30 Sum of positive odd numbers: 35 Sum of negative numbers: 0
Test Case 2
Input (stdin)5 10 -10 20 -20 45
Expected OutputSum of positive even numbers: 30 Sum of positive odd numbers: 45 Sum of negative numbers: -30
No comments:
Post a Comment