Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1. #include <std

ID: 644544 • Letter: H

Question

Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1.

#include <stdio.h>

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;
}

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.

Explanation / Answer

#include <stdio.h>

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;

   for(i = 0; i < NUM_VALS; ++i){
       printf("%d ", courseGrades[i]);
   }
   printf(" ");
   for(i = NUM_VALS - 1; i >= 0; --i){
       printf("%d ", courseGrades[i]);
   }
   printf(" ");
  
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote