We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 74da727 + 84d6c89 commit 5bc513fCopy full SHA for 5bc513f
spiralmatrix.py
@@ -0,0 +1,37 @@
1
+n=int(input("Enter the size of matrix:"))
2
+t=1
3
+r=0 # r stands for row
4
+c=0 # c stands for column
5
+matrix=[[0 for x in range(n)]for y in range(n)] # to initialise the matrix
6
+if n%2==0:
7
+ k=n//2
8
+else:
9
+ k=int((n/2)+1)
10
+for i in range(k):
11
+ while c<n:
12
+ matrix[r][c]=t
13
+ t=t+1
14
+ c=c+1
15
+ r=r+1
16
+ c=c-1
17
+ while r<n:
18
19
20
21
+ r=r-1
22
23
+ while c>=i:
24
25
26
27
28
29
+ while r>i:
30
31
32
33
34
+ n=n-1
35
36
+for m in matrix:
37
+ print(m)
0 commit comments