In C++, we can quickly find array sum using accumulate()
Sum of vector
We can also use a custom function in accumulate. Refer numeric header in C++ STL | Set 1 (accumulate() and partial_sum()) for details.
This article is contributed by kartik. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find original array from encrypted array (An array of sums of other elements)
- Find an element in array such that sum of left array is equal to sum of right array
- Check whether an array can be fit into another array rearranging the elements in the array
- Generate original array from an array that store the counts of greater elements on right
- Find minimum value to assign all array elements so that array product becomes greater
- Print modified array after multiple array range increment operations
- Given a sorted array and a number x, find the pair in array whose sum is closest to x
- Check if there exist two elements in an array whose sum is equal to the sum of rest of the array
- Longest alternating sub-array starting from every index in a Binary Array
- Sort an array where a subarray of a sorted array is in reverse order
- Insert minimum number in array so that sum of array becomes prime
- Find pairs in array whose sums already exist in array
- For each element in 1st array count elements less than or equal to it in 2nd array | Set 2
- Why is it faster to process sorted array than an unsorted array ?
- Find element in array that divides all array elements