Website Statistics write a cprogram by using array to display the average marks obtained by 5 students

Répondre :

#include <iostream>

using namespace std;

int main() {

   // Define an array to store the marks of 5 students

   int marks[5];

   // Input marks for each student

   cout << "Enter marks for 5 students:" << endl;

   for (int i = 0; i < 5; ++i) {

       cout << "Student " << i + 1 << ": ";

       cin >> marks[i];

   }

   // Calculate total marks

   int totalMarks = 0;

   for (int i = 0; i < 5; ++i) {

       totalMarks += marks[i];

   }

   // Calculate average marks

   double averageMarks = totalMarks / 5.0;

   // Display average marks

   cout << "Average marks obtained by 5 students: " << averageMarks << endl;

   return 0;

}

D'autres questions