#include #include //for the iomanipulators setw and setprecision #include using namespace std; int main() { double a[] { //The values trend upwards, with jiggles. 10.00, 11.00, 10.50, 12.00, 11.75, 12.25, 12.00, 12.25, 12.15, 12.50, 12.40, 12.60 }; int n {size(a)}; //the number of elements in the array //Tamp down the jiggles by computing the moving average. for (int i {2}; i < n - 2; ++i) { cout << setw(2) << i << " " << fixed << setprecision(2) << (a[i-2] + a[i-1] + a[i] + a[i+1] + a[i+2]) / 5.0 << "\n"; } cout << "\n"; //Skip a line. for (double *p {a+2}; p < a+n-2; ++p) { //a+2 means &a[2]; a+n-2 means &a[n-2] cout << setw(2) << p - &a[0] << " " << fixed << setprecision(2) << (p[-2] + p[-1] + p[0] + p[1] + p[2]) / 5.0 << "\n"; } return EXIT_SUCCESS; }