using
System;
class
GFG{
static
void
swap(
int
N,
int
M,
int
[,]mat,
int
startx_X,
int
starty_X,
int
startx_Y,
int
starty_Y)
{
int
row = 0;
int
col = 0;
for
(
int
i = startx_X;; i++)
{
col = 0;
for
(
int
j = startx_X;; j++)
{
int
temp = mat[i, j];
mat[i, j] = mat[startx_Y + row,
starty_Y + col];
mat[startx_Y + row, starty_Y + col] = temp;
col++;
if
(col >= M / 2)
break
;
}
row++;
if
(row >= N / 2)
break
;
}
}
static
void
swapQuadOfMatrix(
int
N,
int
M,
int
[,]mat,
int
X,
int
Y)
{
if
(X == 1 && Y == 2)
{
swap(N, M, mat, 0, 0, 0, M / 2);
}
else
if
(X == 1 && Y == 3)
{
swap(N, M, mat, 0, 0, N / 2, 0);
}
else
if
(X == 1 && Y == 4)
{
swap(N, M, mat, 0, 0, N / 2, M / 2);
}
else
if
(X == 2 && Y == 3)
{
swap(N, M, mat, 0, M / 2, N / 2, 0);
}
else
if
(X == 2 && Y == 4)
{
swap(N, M, mat, 0, M / 2, N / 2, M / 2);
}
else
if
(X == 3 && Y == 4)
{
swap(N, M, mat, N / 2, 0, N / 2, M / 2);
}
printMat(N, M, mat);
}
static
void
printMat(
int
N,
int
M,
int
[,]mat)
{
for
(
int
i = 0; i < N; i++)
{
for
(
int
j = 0; j < M; j++)
{
Console.Write(mat[i, j] +
" "
);
}
Console.WriteLine();
}
}
public
static
void
Main(String[] args)
{
int
N = 6, M = 6;
int
[,] mat = {{1, 2, 3, 4, 5, 6},
{7, 8, 9, 10, 11, 12},
{13, 14, 15, 16, 17, 18},
{19, 20, 21, 22, 23, 24},
{25, 26, 27, 28, 29, 30},
{31, 32, 33, 34, 35, 36}};
int
X = 1, Y = 4;
swapQuadOfMatrix(N, M, mat, X, Y);
}
}