const int SIZE = 10; int v[SIZE]; int sum = 0; for (int i = 0; i < SIZE; i++) { v[i] = i * i; sum += v[i]; } cout << "Sum of the first " << SIZE << " squares = " << sum << endl; |
causes the array to look like:
and gives the output:
Sum of the first 10 squares = 285