Cerinta completa

Given an array of integers, find the sum of its elements.

For example, if the array , , so return .

Function Description

Complete the function with the following parameter(s):

  • : an array of integers

Returns

  • : the sum of the array elements

Input Format

The first line contains an integer, , denoting the size of the array.
The second line contains space-separated integers representing the array’s elements.

Constraints

Sample Input

STDIN           Function
-----           --------
6               ar[] size n = 6
1 2 3 4 10 11   ar = [1, 2, 3, 4, 10, 11]

Sample Output

31

Explanation

Print the sum of the array’s elements: .


Limbajul de programare folosit: python3

Cod:

import sys

data = sys.stdin.read().strip().split()
if not data:
    print(0)
else:
    n = int(data[0])
    arr = list(map(int, data[1:1+n]))
    print(sum(arr))

Scor obtinut: 1.0

Submission ID: 464552184

Link challenge: https://www.hackerrank.com/challenges/simple-array-sum/problem

Simple Array Sum