Print a given matrix in spiral form using direction tracking method
Given a 2-D matrix mat[][], the task is to print it in the spiral form.Examples: Input: mat[][] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}} Output: 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 Input: mat[][] = { {1, 2, 3, 4, 5, 6}, {7, 8, 9, 10, 11, 12}, {13, 14, 15, 16, 17, 18}} Ou