Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For C++ ONLY please, Write a for loop to print all elements in courseGrades, fol

ID: 3812777 • Letter: F

Question

For C++ ONLY please,

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:

Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1.

#include <iostream>
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

Explanation / Answer

C++ Program :

#include <iostream>
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
   for(i=0;i<NUM_VALS;i++){
       cout << courseGrades[i] << " ";
   }
   cout << endl;
   for(i=NUM_VALS-1;i>=0;i--){
       cout << courseGrades[i] << " ";
   }
   cout << endl;
}

OUTPUT :

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote