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
#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;
}
Comments
Leave a comment