From 64b37958cd35f8b38a3d7f45fbb67cd561b1df0a Mon Sep 17 00:00:00 2001 From: samarps31 Date: Thu, 8 Oct 2020 09:44:56 +0530 Subject: [PATCH] Spiral Matrix --- Beginner/Spiral matrix.cpp | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Beginner/Spiral matrix.cpp diff --git a/Beginner/Spiral matrix.cpp b/Beginner/Spiral matrix.cpp new file mode 100644 index 00000000..7542ea04 --- /dev/null +++ b/Beginner/Spiral matrix.cpp @@ -0,0 +1,55 @@ +// Program to create a spiral matrix by entering order of matrix (it is a square matrix) + +#include +#include +main() +{ + int i=0,j=0,s=0,n,A[100][100],a=0; + + printf("Enter no. of rows or columns of the square matrix = "); + scanf("%d",&n); + + do + { + a+=1; + + for(j;j<=n-a;j++) + { + s+=1; + A[i][j]=s; + } + + j-=1; + for(i+=1;i<=n-a;i++) + { + s+=1; + A[i][j]=s; + } + i-=1; + + for(j-=1;j>=a-1;j--) + { + s+=1; + A[i][j]=s; + } + j+=1; + + for(i-=1;i>a-1;i--) + { + s+=1; + A[i][j]=s; + } + j+=1; + i+=1; + + }while(a