C#
using System; using System.Linq;
class Program { static void Main() { int N = 3; // number of students int M = 4; // number of subjects
int[,] marks = { { 90, 80, 70, 60 }, // marks of student 1 { 85, 75, 65, 55 }, // marks of student 2 { 80, 70, 60, 50 } // marks of student 3 };
int[] sum = new int[N]; // array to store total marks of each student int minSubject = 0; double minAvg = double.MaxValue;
for (int j = 0; j < M; j++) { double avg = 0; for (int i = 0; i < N; i++) { avg += marks[i,j]; sum[i] += marks[i,j]; } avg /= N; if (avg < minAvg) { minAvg = avg; minSubject = j; } }
for (int i = 0; i < N; i++) { sum[i] -= marks[i,minSubject]; }
Console.WriteLine("Subject to ignore: " + (minSubject+1)); Console.WriteLine("Total marks of each student in all other subjects:"); for (int i = 0; i < N; i++) { Console.WriteLine("Student " + (i+1) + ": " + sum[i]); } } }