Answer to Question #234728 in C++ for Tarurendra Kushwah

Question #234728

Consider an array MARKS[20][5] which stores the marks obtained by 20 students in 5 subjects. Now write a program to

(a) find the average marks obtained in each subject.

(b) find the average marks obtained by every student.

(c) find the number of students who have scored below 50 in their average.

(d) display the scores obtained by every student.


1
Expert's answer
2021-09-08T16:03:43-0400
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	  //Declaring and initializing 5 subjects for each students. There are 20 students declared
 
 int MARKS[20][5] = {{48,27,10,67,18},{58,89,40,80,78},{47,40,49,78,40},{69,40,89,88,67},{38,91,76,34,67},{66,45,89,34,90},{97,78,90,67,56},
					{57,78,90,87,76}, {77,98,50,57,46}, {57,98,70,67,86}, {77,68,70,67,56}, {97,98,90,67,56}, {67,78,90,67,56}, {27,48,60,87,56},
					{17,58,90,97,86}, {67,78,90,67,56}, {37,58,90,67,56}, {77,78,70,67,66}, {67,78,90,67,56}, {97,88,90,67,76}};




double total = 0;
double average = 0;
//Answer to part (a)
cout<<"Average marks for each subject\n";
cout<<"Subject     \tAverage\n";
for (int i = 0; i < 5; i++)
{
   for (int j = 0; j < 20; j++)
   {
       total += MARKS[i][j];
   }
   average = total/20;
 
   cout <<(i+1)<<":   \t\t  " << average << endl;
   
   average = 0;
   total = 0;
}
int count =0;
double averageScore[20];
//Answer of part (b)
cout<<"Average marks for every student\n";
cout<<"Student     \tAverage\n";
for(int i=0; i<20; i++){
	double total = 0;
	for(int j=0; j<5; j++){
		total +=  MARKS[i][j];
	}
	cout<<(i+1)<<":   \t\t  " << total / 5 <<endl;
	averageScore[i] = total / 5;
}
for(int i=0; i<20; i++){
if(averageScore[i]<50){
	count++;
}
}
//Answer to part (c)
cout<<"The number of students with average less than 50:\t"<<count<<endl;
//Answer to part (d)
cout<<"Average marks obtained by every student\n";
cout<<"Student     \tScores\n";
for(int i=0; i<20; i++){
	cout<<(i+1)<<":   \t\t  " <<averageScore[i] * 5 <<endl;
}
}

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