84. Sum an Array Through a Pointer
Core1000 ms256 MBSolved by 0%
Read n and then n integers, and print their sum.
The exercise is to walk the array using a moving pointer rather than an index, in C
and C++, *p then p++. In other languages, walk with an iterator rather than an
index, which is the same idea without the arithmetic.
Constraints - `1 ≤ n ≤ 100000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print one integer, the sum of every element.
Input5
1 2 3 4 5
Output15
Noteis a small positive array
Input3
-1 -2 -3
Output-6
Noteis entirely negative
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.