using
System;
using
System.Linq;
class
GFG
{
static
int
[,] Transpose(
int
[,] mat,
int
row,
int
col)
{
int
[,] tr =
new
int
[col, row];
for
(
int
i = 0; i < row; i++)
{
for
(
int
j = 0; j < col; j++)
{
tr[j, i] = mat[i, j];
}
}
return
tr;
}
static
void
RowWiseSort(
int
[,] B,
int
row,
int
col)
{
for
(
int
i = 0; i < row; i++)
{
int
[] rowElements = Enumerable.Range(0, col).Select(x => B[i, x]).ToArray();
Array.Sort(rowElements);
for
(
int
j = 0; j < col; j++)
{
B[i, j] = rowElements[j];
}
}
}
static
void
SortCol(
int
[,] mat,
int
N,
int
M)
{
int
[,] B = Transpose(mat, N, M);
RowWiseSort(B, M, N);
mat = Transpose(B, M, N);
for
(
int
i = 0; i < N; i++)
{
for
(
int
j = 0; j < M; j++)
{
Console.Write(mat[i, j] +
" "
);
}
Console.Write(
"\n"
);
}
}
public
static
void
Main(
string
[] args)
{
int
[, ] mat = { { 1, 6, 10 },
{ 8, 5, 9 },
{ 9, 4, 15 },
{ 7, 3, 60 } };
int
N = mat.GetLength(0);
int
M = mat.GetLength(1);
SortCol(mat, N, M);
}
}