Advertisement
bhok

Array Summation

Jul 2nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. // More Code Tutorials from Brandonhok.com
  2. // Summing all elements of an array
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.     const int arraySize = 10;
  11.     int a[arraySize] = { 87,11,22,55,33,66,11,42,80,11 };
  12.     int total = 0;
  13.  
  14.     for (int i = 0; i < arraySize; ++i)
  15.         total += a[i];
  16.  
  17.     cout << "Total of array elements: " << total << endl;
  18.     system("pause");
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement