Assuming it's already late, and this is more extravagant than your teacher would expect, this would work:
Code:
class Program
{
private static void Main(string[] args)
{
int[,] matrix = new int[4, 5]
{
{ 5, 7, 3, 4, 8 },
{ 4, 5, 9, 4, 6 },
{ 3, 10, 6, 7, 5 },
{ 6, 4, 8, 1, 9 }
};
int[,] maxes = new int[4, 5];
for (int row = 0; row <= matrix.GetUpperBound(0); ++row)
{
for (int column = 0; column <= matrix.GetUpperBound(1); ++column)
{
maxes[row, column] = matrix.GetMaxValue(row, column);
}
}
for (int row = 0; row <= matrix.GetUpperBound(0); ++row)
{
for (int column = 0; column <= matrix.GetUpperBound(1); ++column)
Console.Write("{0,2} ", maxes[row, column]);
Console.WriteLine();
}
}
}
public static class Extensions
{
public static int GetMaxValue(this int[,] matrix, int row, int column)
{
int max = int.MinValue;
for (int c = 0; c <= matrix.GetUpperBound(1); ++c)
if (max < matrix[row, c])
max = matrix[row, c];
for (int r = 0; r <= matrix.GetUpperBound(0); ++r)
if (max < matrix[r, column])
max = matrix[r, column];
return max;
}
}
Output:
Code:
8 10 9 8 9
9 10 9 9 9
10 10 10 10 10
9 10 9 9 9