Easy 0 solved 0% acceptance

Sum an Array

Add up all values in a list.

Problem

Return the total of all numbers in the list. An empty list sums to 0.

Implement sum_array(numbers).

Input

numbers: The list of integers.

Output

Return the sum.

Constraints

0 ≤ length ≤ 100,000; the total fits in a 64-bit integer

Examples

Example 1
Input:
numbers = [1, 2, 3, 4]

Expected output:
expected = 10
Input:
std::vector<long long> numbers = {1, 2, 3, 4};

Expected output:
long long expected = 10;
Input:
long[] numbers = new long[] {1, 2, 3, 4};

Expected output:
long expected = 10;

Explanation

1 + 2 + 3 + 4 = 10.

Example 2
Input:
numbers = []

Expected output:
expected = 0
Input:
std::vector<long long> numbers = {};

Expected output:
long long expected = 0;
Input:
long[] numbers = new long[] {};

Expected output:
long expected = 0;

Explanation

Nothing to add: 0.

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.