C Exercises: Print a matrix in spiral form
50. Spiral Matrix Print
Write a program in C to print a matrix in spiral form.
This task involves writing a C program to print a given matrix in spiral order. The program will take a 2D array as input, display the matrix in its original form, and then output the elements in a spiral traversal order starting from the top-left corner.
Visual Presentation:

Sample Solution:
C Code:
Sample Output:
The given array in matrix form is : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 The spiral form of above matrix is: 1 2 3 4 5 10 15 20 19 18 17 16 11 6 7 8 9 14 13 12
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to print a matrix in spiral order and then reverse the spiral order.
- Write a C program to display a matrix in spiral form using recursion.
- Write a C program to output a spiral matrix and then rotate the matrix by 90 degrees.
- Write a C program to print a matrix in spiral order and compute the sum of the spiral elements.
C Programming Code Editor:
Previous: Write a program in C to find majority element of an array.
Next: Write a program in C to find the maximum circular subarray sum of a given array.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.