198k views
0 votes
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

1 Answer

7 votes

Answer:

The code is given below in C with appropriate comments at the sample example

Step-by-step explanation:

#include <stdio.h>

int main(void) {

const int NUM_VALS = 4;

int courseGrades[NUM_VALS];

int i = 0;

// taking examples of course grades

courseGrades[0] = 7;

courseGrades[1] = 9;

courseGrades[2] = 11;

courseGrades[3] = 10;

for(int i = 0; i < NUM_VALS; i++)

printf("%i ", courseGrades[i]);

printf("\\");

for(int i = NUM_VALS-1; i >= 0; i--)

printf("%i ", courseGrades[i]);

printf("\\");

return 0;

}

User Functionaldude
by
8.8k points