Write a C program that lets the user enters 5 students test
Write a C++ program that lets the user enters 5 students’ test scores for three classes and calculates the average test scores for each student. Display the test scores for each student and display the average of the test scores for each student as well. You need to use two dimensional array for this program and to use two nested loops to read and calculate the average test scores.
Solution
//code has been tested on gcc compiler
#include <iostream>
using namespace std;
int main()
{int std[5][3]; //two dimensional array for storing 5 students scores of 3 classes
double avg_score[5]; //array for storing average score of 5 students
double avg; //variable for storing average value
cout << \"Enter the test scores of 3 classes for 5 students\" << endl; //asking the user to enter scores of 3 //classes for each student
for(int i=0;i<5;i++) //nested loop
{avg=0;
for(int j=0;j<3;j++)
{
cin>>std[i][j]; //reading the test scores
avg=avg+std[i][j]; //calculating the average scores
}
avg=double(avg)/3.0;
avg_score[i]=avg; //storing the average scores in the average array for //each student
}
for(int i=0;i<5;i++){ //loop to display scores and average score for each //student
cout<<\"Student \"<<i+1<<\" scores in 3 subjects are \"<<endl;
for(int j=0;j<3;j++)
{
cout<<std[i][j]<<\" \";
}
cout<<\"Average of the test scores for \"<<i+1<<\" student is \"<<avg_score[i]<<endl;
}
return 0;
}
//end of code
*********OUTPUT**********
Enter the test scores of 3 classes for 5 students
1
2
3
7
3
3
5
6
7
4
6
4
8
9
Student 1 scores in 3 subjects are
1 2 3 Average of the test scores for 1 student is 2
Student 2 scores in 3 subjects are
7 3 3 Average of the test scores for 2 student is 4.33333
Student 3 scores in 3 subjects are
5 6 7 Average of the test scores for 3 student is 6
Student 4 scores in 3 subjects are
4 6 1 Average of the test scores for 4 student is 3.66667
Student 5 scores in 3 subjects are
4 8 9 Average of the test scores for 5 student is 7
*********OUTPUT**********
Please let me know in case of any doubt,Thanks.

