QUESTION IMAGE
Question
712986 5539894.qx3zqy7
or the lines of code to create two for loops that print all elements in coursegrades, following each element with a space including the last. print forwards, then backwards. after each loop, print a newline.
ex: if the input is 7 9 11 10, then the output is:
7 9 11 10
10 11 9 7
how to use this tool
unused
cout << coursegradesi << \ \;
}
cout << coursegradesi << \ \;
cout << endl;
}
for (i = num_vals - 1; i >= 0; --i) {
cout << endl;
for (i = 0; i < num_vals; ++i) {
main.cpp
load default template...
#include <iostream>
using namespace std;
int main() {
const int num_vals = 4;
int coursegradesnum_vals;
int i;
for (i = 0; i < num_vals; ++i) {
cin >> coursegradesi;
}
return 0;
}
Step1: Add forward loop
for (i = 0; i < NUM_VALS; ++i) {
cout << courseGrades[i] << " ";
}
cout << endl;
Step2: Add backward loop
for (i = NUM_VALS - 1; i >= 0; --i) {
cout << courseGrades[i] << " ";
}
cout << endl;Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
The completed main.cpp code is:
#include <iostream>
using namespace std;
int main() {
const int NUM_VALS = 4;
int courseGrades[NUM_VALS];
int i;
for (i = 0; i < NUM_VALS; ++i) {
cin >> courseGrades[i];
}
// Forward print loop
for (i = 0; i < NUM_VALS; ++i) {
cout << courseGrades[i] << " ";
}
cout << endl;
// Backward print loop
for (i = NUM_VALS - 1; i >= 0; --i) {
cout << courseGrades[i] << " ";
}
cout << endl;
return 0;
}
When given input 7 9 11 10, the output will be:
7 9 11 10
10 11 9 7