Given the set of integers, find the sum of all positive integers in it. Solutions can be sent in any language supported by SPOJ except Whitespace.
Input
t – number of test cases [t < 1000]
On each of next t lines given a integer N [-1000 <= N <= 1000]
Output
One integer equals to sum of all positive integers.
Score
Score equals to size of source code of your program except symbols with ASCII code <= 32.
Example
1 2 3 4 5 6 7 8 |
<b>Input:</b> 4 5 -5 6 -1 <b>Output:</b> 11 |
C Program :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> int main() { unsigned long sum=0; short n,a,i; scanf("{b15f91eef52e7c6d40fd3fe45227e26332e4c02be027e4e72c6ecf7adacefb97}hu",&n); for(i=0;i<n;i++) { scanf("{b15f91eef52e7c6d40fd3fe45227e26332e4c02be027e4e72c6ecf7adacefb97}hu",&a); if(a>0) sum+=a; } printf("\n{b15f91eef52e7c6d40fd3fe45227e26332e4c02be027e4e72c6ecf7adacefb97}lu",sum); return 0; } |
Recent Comments