Question: Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each
Write a for loop to print all elements in 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.
my code:
#include
int main() { const int NUM_VALS = 4; int courseGrades[NUM_VALS]; int i;
for (i = 0; i < NUM_VALS; ++i) { cin >> courseGrades[i]; } for (i = 0; i < NUM_VALS; i++) { cout << " " << courseGrades[i] << endl; }
for (i = NUM_VALS - 1; i >= 0; i--) { cout << " " << courseGrades[i] << endl; } /* Your solution goes here */
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
