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
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution