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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to find the sum of elements of an Array using STL in C++?
- Sorting an array according to another array using pair in STL
- array::front() and array::back() in C++ STL
- array::fill() and array::swap() in C++ STL
- array::begin() and array::end() in C++ STL
- array::crbegin() and array::crend() in C++ STL
- array::cbegin() and array::cend() in C++ STL
- array::rbegin() and array::rend() in C++ STL
- Find an element in array such that sum of left array is equal to sum of right array
- How to find the sum of elements of a Vector using STL in C++?
- Array algorithms in C++ STL (all_of, any_of, none_of, copy_n and iota)
- Sorting Array Elements By Frequency | Set 3 (Using STL)
- array::operator[ ] in C++ STL
- array::size() in C++ STL
- array::empty() in C++ STL
- array::at() in C++ STL
- array::max_size() in C++ STL
- Count the number of 1's and 0's in a binary array using STL in C++ ?
- Array product in C++ using STL
- array data() in C++ STL with Examples