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

Programming In C homework Objectives: Array Manipulations a) Initializing an Arr

ID: 3759527 • Letter: P

Question

Programming In C homework

Objectives: Array Manipulations

a) Initializing an Array

b) Loading an Array

c) Summation of an Array

d) Unloading (printing an Array)

Write an interactive program to prompt and enter scores for 13 students. Then have computer to calculate and print out scores and class average. Similar program is in your textbook.

The program must produce the following Output:

Please enter number of students in this class: 13

Enter a grade: 67

Enter a grade: 92

.

.

.

.

.

.

.

Enter a grade: 76

The scores were entered are: 67 92 ………………………………76

The class average for this test is : 71.45

Explanation / Answer

#include <stdio.h>

int main() {


   //prompt and enter scores for 13 students.
   printf("Please enter number of students in this class: ");
   int nOfscores;
   scanf("%d", &nOfscores);
   if(nOfscores > 0) {
       int grades[nOfscores];

       // Initializing an Array
       int i;
       for(i =0; i < nOfscores; i++)
           grades[i] = 0;

       // Loading an Array

       int score = 0;
       for(i =0; i < nOfscores; i++) {
           printf(" Enter a grade: ");
           scanf("%d",&score);
           grades[i] = score;
       }

       //c) Summation of an Array
       int total = 0;
       for(i =0; i < nOfscores; i++) {
           total += grades[i];

       }

       float avg = total/nOfscores;
       //d) Unloading (printing an Array)
       printf(" The scores were entered are: ");
       for(i =0; i < nOfscores; i++) {
           printf(" %d",grades[i]);
       }

       printf(" The class average for this test is : %f ",avg);

   } else
       printf("Invalid number");
}

-----------------output---------------------

Please enter number of students in this class: 4
Enter a grade: 50
Enter a grade: 60
Enter a grade: 70
Enter a grade: 80
The scores were entered are: 50 60 70 80
The class average for this test is : 65.000000