1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
enyata [817]
3 years ago
9

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.

#include

int main(void) {
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 */
return 0;
}
Computers and Technology
1 answer:
konstantin123 [22]3 years ago
4 0

Answer:

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;

Explanation:

The first loop initializes i with 0, because we have to print the elements in order in which the appear in the array. We print each element, adding a space (" ") character at its end. After the loop ends, we add a new line using endl.

The second loop will print the values in a reverse order, so we initialize it from NUM_VALS-1, (since NUM_VALS = 4, and array indices are 0,1,2,3). We execute the loop till i >= 0, and we print the space character and new line in a similar way we executed in loop1.

You might be interested in
This is going to get taken down but I dont care add me on discord cause ima bored<br> -Red-#9847
Alex777 [14]

Answer:

I WILL

Explanation:

6 0
2 years ago
Well I am having trouble and I feel really bad because I helped RandomGuy1 who rubs it in my face that I gave him the wrong answ
yawa3891 [41]
Hey dude don't leave tell a mod bout it they'll fix everything up for you.
8 0
3 years ago
Match each of the following terms to its function:_________
Crazy boy [7]

Answer:

I = B

II = E

III = A

IV = D

V = C

7 0
3 years ago
What pointer appears when pointing to a hyperlink
Leokris [45]
Your answer would be: a hand pointer.
6 0
3 years ago
Read 2 more answers
A social media site violates its terms of service by selling information about its users
balu736 [363]
A company violating its terms of service by selling their user’s info is a violation of Digital Privacy
4 0
2 years ago
Other questions:
  • Binary search requires that data to search be in order. true or false
    5·1 answer
  • You can use RWA to demonstrate how to do something special on the web, such as displaying articles found on websites that suppor
    15·1 answer
  • Complete the function void update (int *a, int *b), which reads two integers as argument, and sets a with the sum of them, and b
    8·1 answer
  • Which code will allow Joe to print Coding is fun. on the screen? print("Coding is fun.") print(Coding is fun.) print = (Coding i
    10·2 answers
  • What do the buttons on the paste options menu do
    11·1 answer
  • Write a program named RectangleArea to calculate the area of a rectangle with a length of 15.8 and a width of 7.9. The program s
    10·1 answer
  • [1] Our son has started playing organized T-ball, a beginner’s version of baseball. [2] “Organized” is what parents call it, any
    9·2 answers
  • The most important hardware device for connecting supercomputers over a wide area
    10·1 answer
  • How many atoms of oxygen in 4 molecules of HN03​
    12·1 answer
  • A computer game allows a player to repeat a level until they run out of lives. Which two of the following loops would work corre
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!