Print Grid

Published by persolut in

Write a method that accepts two integer parameters rows and cols. The output is a 2d array of numbers displayed in column-major order, meaning the numbers shown increase sequentially down each column and wrap to the top of the next column to the right once the bottom of the current column is reached.

Examples

PrintGrid(3, 6) ➞ new int[,] { 
  new int[] { 1, 4, 7, 10, 13, 16 },
  new int[] { 2, 5, 8, 11, 14, 17 },
  new int[] { 3, 6, 9, 12, 15, 18 }
]

PrintGrid(5, 3) ➞ new int[,] { 
  new int[] { 1, 6, 11 },
  new int[] { 2, 7, 12 },
  new int[] { 3, 8, 13 },
  new int[] { 4, 9, 14 },
  new int[] { 5, 10, 15 }
]

PrintGrid(4, 1) ➞ new int[,] { 
  new int[] { 1 },
  new int[] { 2 },
  new int[] { 3 },
  new int[] { 4 }
]

Notes

The return type of the function must be a 2 dimensional array of integers - int[,]

Watch a quick demo on how Edabit works.