archangelmihail

PrintMatrix

Dec 29th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. static void PrintMatrix(int[,] matrix)
  2.     {
  3.         int max = matrix[0, 0];
  4.         foreach (int cell in matrix) max = Math.Max(max, cell);
  5.         int cellSize = (int)Math.Log10(Math.Max(max, 1)) + 1;
  6.  
  7.         for (int i = 0; i < matrix.GetLength(0); i++)
  8.             for (int j = 0; j < matrix.GetLength(1); j++)
  9.                 Console.Write(Convert.ToString(matrix[i, j]).PadRight(cellSize, ' ') + (j != matrix.GetLength(1) - 1 ? " " : "\n"));
  10.     }
Advertisement
Add Comment
Please, Sign In to add comment