Sum of Array Elements
EasyPractice library · +10 XPrecursionarraysiteration
Given a list of N integers, compute and print their sum. The integers can be positive, negative, or zero.
Input
The first line contains an integer N, representing the number of elements. The second line contains N space-separated integers.
Output
Print a single integer, the sum of the N integers.
Constraints
1 <= N <= 1000 -1000 <= element <= 1000
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
5 1 2 3 4 5
Output
15
The sum of 1, 2, 3, 4, and 5 is 15.
Example 2
Input
3 -1 0 1
Output
0
The sum of -1, 0, and 1 is 0.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 1 2 3 4 5
Example 2 input
3 -1 0 1