Sum of Array
Practice this coding question on Coding Gurukul.
Problem statement
A warehouse records changes to its stock throughout a shift. Positive entries represent arrivals and negative entries represent items sent out. Your task Compute the sum of all n integers in the array to obtain the net stock change. Important details Include every entry exactly once, even if some values repeat. Negative entries subtract from the total, and zero entries leave it unchanged. The result may be negative, zero, or positive. This exercise asks for the total over the entire array, not the largest subarray sum or the number of deliveries. Accumulate in a 64-bit integer because many individually small changes can produce a large total. Worked example For changes 8, -3, 0, and 6, the net change is 8 - 3 + 0 + 6 = 11.
Input format
The first line contains n. The second line contains n space-separated integers.
Output format
Print the exact sum of the array.
Constraints
1 <= n <= 100000; -1000000000 <= a[i] <= 1000000000.
Sample input
4 8 -3 0 6
Sample output
11
Sign in to run or submit a solution in C++, Java or Python.