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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Find Array formed by adding each element of given array with largest element in new array to its left
- Minimum number of operations to convert array A to array B by adding an integer into a subarray
- Minimum cost to reach end of array array when a maximum jump of K index is allowed
- Find array sum using Bitwise OR after splitting given array in two halves after K circular shifts
- Print modified array after multiple array range increment operations
- Find Kth number from sorted array formed by multiplying any two numbers in the array
- Minimum number greater than the maximum of array which cannot be formed using the numbers in the array
- Count elements in first Array with absolute difference greater than K with an element in second Array
- Generate original array from an array that store the counts of greater elements on right
- Count number of permutation of an Array having no SubArray of size two or more from original Array
- Maximize the size of array by deleting exactly k sub-arrays to make array prime
- Find minimum value to assign all array elements so that array product becomes greater
- Check if it is possible to make array increasing or decreasing by rotating the array
- Number of ways to change the Array such that largest element is LCM of array
- Find starting index for every occurrence of given array B in array A using Z-Algorithm
- Generate Array whose difference of each element with its left yields the given Array
- Maximum subarray sum in array formed by repeating the given array k times
- Find K such that changing all elements of the Array greater than K to K will make array sum N