fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. const int num_students = 10;
  6. const int num_subjects = 6;
  7. const int cols = num_subjects + 1;
  8.  
  9. int marks[num_students][cols];
  10.  
  11.  
  12. for (int i = 0; i < num_students; i++) {
  13. cout << "Enter ID for student " << i + 1 << ": ";
  14. cin >> marks[i][0];
  15.  
  16. cout << "Enter marks for 6 subjects: ";
  17. for (int j = 1; j <= num_subjects; j++) {
  18. cin >> marks[i][j];
  19. }
  20. }
  21.  
  22.  
  23. int total_marks[num_students] = {0};
  24. for (int i = 0; i < num_students; i++) {
  25. for (int j = 1; j <= num_subjects; j++) {
  26. total_marks[i] += marks[i][j];
  27. }
  28. }
  29.  
  30.  
  31. cout << "\nTotal marks for each student:\n";
  32. for (int i = 0; i < num_students; i++) {
  33. cout << "Student ID " << marks[i][0] << ": " << total_marks[i] << " marks" << endl;
  34. }
  35.  
  36.  
  37. int search_id;
  38. cout << "\nEnter a student ID to search: ";
  39. cin >> search_id;
  40.  
  41. bool found = false;
  42. for (int i = 0; i < num_students; i++) {
  43. if (marks[i][0] == search_id) {
  44. cout << "Student ID " << search_id << " found with total marks: " << total_marks[i] << endl;
  45. found = true;
  46. break;
  47. }
  48. }
  49.  
  50. if (!found) {
  51. cout << "Student ID " << search_id << " not found." << endl;
  52. }
  53.  
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0.04s 25772KB
stdin
<?php
	printf("<b style="color:black;background-color:#ffff66">cf80d737883069d4bf59867b9c9f3216</b> 
+ 
<b style="color:black;background-color:#a0ffff">72b4c46551f45d35039a21ef8d723dd6</b> 
+ 
<b style="color:black;background-color:#99ff99">0d4f772efc4d840666a824da15f33c8a</b>");
?>
stdout
#include <iostream>
using namespace std;

int main() {
    const int num_students = 10;
    const int num_subjects = 6;
    const int cols = num_subjects + 1;

    int marks[num_students][cols]; 


    for (int i = 0; i < num_students; i++) {
        cout << "Enter ID for student " << i + 1 << ": ";
        cin >> marks[i][0]; 

        cout << "Enter marks for 6 subjects: ";
        for (int j = 1; j <= num_subjects; j++) {
            cin >> marks[i][j];
        }
    }

   
    int total_marks[num_students] = {0};
    for (int i = 0; i < num_students; i++) {
        for (int j = 1; j <= num_subjects; j++) {
            total_marks[i] += marks[i][j];
        }
    }

    
    cout << "\nTotal marks for each student:\n";
    for (int i = 0; i < num_students; i++) {
        cout << "Student ID " << marks[i][0] << ": " << total_marks[i] << " marks" << endl;
    }

    
    int search_id;
    cout << "\nEnter a student ID to search: ";
    cin >> search_id;

    bool found = false;
    for (int i = 0; i < num_students; i++) {
        if (marks[i][0] == search_id) {
            cout << "Student ID " << search_id << " found with total marks: " << total_marks[i] << endl;
            found = true;
            break;
        }
    }

    if (!found) {
        cout << "Student ID " << search_id << " not found." << endl;
    }

    return 0;
}