#include <iostream>
using namespace std;
int main()
{
//Create an array of 8 integers called data
int data[8];
//Initialized the 0th index of the array to 1 and print out the data
int y = 1;
data[0] = y;
cout << data[0] << " ";
//By looking at the range of the for loop, we can see it will go from [1, 7] (inclusive of both)
for(int i=1; i < 8; i++){
//Increase our y value by two
y += 2;
//Set the ith index of data to the value of the previous index + y and print that value
data[i] = data[i-1] + y;
cout << data[i] << " ";
/* The values that are printed by this line are as follows:
4 9 16 25 36 49 64
If you notice this are the second through eigth squares (numbers of value n^2)
This is a property seen naturally in the real world such as physics in terms of distance and
time (Source: http://www.mcm.edu/academic/galileo/ars/arshtml/mathofmotion1.html) */
}
cout << endl;
//We can see that this for loop goes from [0, 4] (inclusive of both)
int s = 0;
for(int i=0; i < 5; i++){
//s gets the average of two adjacent pairs in the array
s += (data[i] + data[i+1])/2;
/* The values of s throughout the running of this loop are as follows:
s = 2, s = 8, s = 20, s = 40, s = 70
*/
}
//This prints out the final sum of averages, which is 70
cout << s << endl;
return 0;
}
/* Program Output:
1 4 9 16 25 36 49 64
70
*/