Answer to Question #330275 in C++ for smoak

Question #330275

write a 2D array to show average of 5 subjects for 20 students


1
Expert's answer
2022-04-18T15:19:53-0400
#include <iostream>
using namespace std;


void readData(int studentsMarks[20][5])  {
        for (int i=0; i<20; i++) {
            cout << "Enter marks for " << i+1 << "-th student: ";
            for (int j=0; j<5; j++) {
                cin >> studentsMarks[i][j];
            }
        }
}


void printAverage(int studentsMarks[20][5]) {
    int sum;
    double avg;


    for (int i=0; i<20; i++) {
        sum = 0;
        for (int j=0; j<5; j++) {
            sum += studentsMarks[i][j];
        }
        avg = sum / 5.0;
        cout << "Average mark for student " << i+1 << " is " << avg << endl;
    }
}


int main() {
    int studentsMarks[20][5];


    readData(studentsMarks);
    printAverage(studentsMarks);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS