public static void input2DIntArr(out int[,] arr)
Console.Write("Nhap n cua mang n x m: ");
int n = Int32.Parse(Console.ReadLine());
Console.Write("Nhap m cua mang n x m: ");
int m = Int32.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
Console.Write("Nhap phan tu [{0},{1}] cua mang: ", i, j);
arr[i,j] = Int32.Parse(Console.ReadLine());
public static void input1DDoubleArray(out double[] arr)
Console.Write("Nhap so phan tu cua mang: ");
int n = Int32.Parse(Console.ReadLine());
for (int i = 0; i < arr.Length; i++)
Console.Write("Nhap phan tu {0} cua mang: ", i);
arr[i] = Double.Parse(Console.ReadLine());
public static void input1DIntArray(out int[] arr)
Console.Write("Nhap so phan tu cua mang: ");
int n = Int32.Parse(Console.ReadLine());
for (int i = 0; i < arr.Length; i++)
Console.Write("Nhap phan tu {0} cua mang: ", i);
arr[i] = Int32.Parse(Console.ReadLine());
public static void output1DArray(object[] array)
Console.WriteLine("Cac phan tu trong mang: ");
for (int i = 0; i < array.Length; i++)
Console.WriteLine("[{0}] : {1}", i, array[i]);
public static void output2DIntArr(int[,] arr)
for (int i = 0; i < arr.GetLength(0); i++)
for (int j = 0; j < arr.GetLength(1); j++)
Console.Write(arr[i,j] + " ");
public static void swapValue(ref int a, ref int b)
public static void bubbleSort_Increasing(ref int[] array)
for (int i = 0; i < array.Length; i++)
for(int j = array.Length - 1; j > i; j--)
if (array[j] < array[j-1])
swapValue(ref array[j], ref array[j-1]);
static int[] convert2DArrTo1DArr(int[,] arr)
int[] _1DArr = new int[arr.GetLength(0)*arr.GetLength(1)];
for (int i = 0; i < arr.GetLength(0); i++)
for(int j = 0; j < arr.GetLength(1); j++)
_1DArr[index] = arr[i,j];
static void convert1DArrTo2DArr(int[] arr, ref int[,] res)
for (int i = 0; i < res.GetLength(0); i++)
for(int j = 0; j < res.GetLength(1); j++)
static void solve319(ref int[,] arr)
int n = arr.GetLength(0);
int m = arr.GetLength(1);
int[] tempArr = convert2DArrTo1DArr(arr);
Sort.bubbleSort_Increasing(ref tempArr);
convert1DArrTo2DArr(tempArr, ref arr);
public static void Main()
Array.input2DIntArr(out arr);
Array.output2DIntArr(arr);