// C# program to find column
// with max difference of
// any pair of elements
using System;
class GFG
{
static int N = 5; // No of rows and column
// Function to find the column
// with max difference
static int colMaxDiff(int [,]mat)
{
int max_diff = int.MinValue;
// Traverse matrix column wise
for (int i = 0; i < N; i++)
{
// Insert elements of column
// to vector
int max_val = mat[0, i],
min_val = mat[0, i];
for (int j = 1; j < N; j++)
{
max_val = Math.Max(max_val,
mat[j, i]);
min_val = Math.Min(min_val,
mat[j, i]);
}
// calculating difference between
// maximum and minimum
max_diff = Math.Max(max_diff,
max_val - min_val);
}
return max_diff;
}
// Driver Code
public static void Main()
{
int [,]mat = { { 1, 2, 3, 4, 5 },
{ 5, 3, 5, 4, 0 },
{ 5, 6, 7, 8, 9 },
{ 0, 6, 3, 4, 12 },
{ 9, 7, 12, 4, 3 }};
Console.WriteLine("Max difference : " +
colMaxDiff(mat));
}
}
// This code is contributed
// by Subhadeep