Write a for loop to print all NUM_VALS elements of vector courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print:7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1.#include using namespace std;int main() {const int NUM_VALS = 4;int courseGrades[NUM_VALS];int i = 0;courseGrades[0] = 7;courseGrades[1] = 9;courseGrades[2] = 11;courseGrades[3] = 10;//Your solution goes here

Respuesta :

ijeggs

Answer:

#include <iostream>

using namespace std;

int main()

{

int courseGrades [ ] = {7, 9, 11, 10};

for(int i =0; i<4; i++){

       cout<<courseGrades[i]<<" ";

}

for(int j = 3; j>=0; j--){

   cout<<courseGrades[j]<<" ";

}

}

Explanation:

Using C++ programming language

Create the array vector and assign values with this statement int courseGrades [ ] = {7, 9, 11, 10};

The first for loop prints the values from 0-4 (Since four values are given and hard coded) for(int i =0; i<4; i++)

The second for loop prints from the last to the first element (i.e reversed) for(int j = 3; j>=0; j--)