C++:Sum an Array
You can add the numbers in the array [6,7,29] using a loop.
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Alternatively, you can use the library function accumulate()
:
#include <iostream> #include <numeric> using namespace std; int main(){ int a[] = {6,7,29}; cout << accumulate(a, a+3, 0) << endl; return 0; }