Answer to Question #259999 in C++ for aria

Question #259999

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 
1
Expert's answer
2021-11-02T00:38:39-0400
#include <iostream>


using namespace std;


int main(void)
{
    const int num_val=4;
    int courseGrades[num_val];
    int i;
    courseGrades[0]=7;
    courseGrades[1]=9;
    courseGrades[2]=11;
    courseGrades[3]=10;
    for(i=0;i<num_val;++i){
        cout<<courseGrades[i];
        if(i!=num_val-1){
            cout<<" ";
        }
    }
     cout << "\n" ;
     for(i=num_val-1;i>=0;--i){
        cout<<courseGrades[i];
        if(i!=0){
            cout<<" ";
        }
    }
    cout << "\n";
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS