We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d6451aa commit 8e89391Copy full SHA for 8e89391
magicsquare.py
@@ -0,0 +1,44 @@
1
+def magic(n):
2
+ print("Study The Rule First Then start Program")
3
+ magic=[]
4
+ for i in range(n):
5
+ l=[]
6
+ for j in range(n):
7
+ l.append(0)
8
+ '''l.append(j) is one of mistake'''
9
+ magic.append(l)
10
+
11
12
+ i=n//2
13
+ j=n-1
14
+ count=n*n
15
+ sum=int((n*(n**2 +1))/2)
16
+ print("Sum Of The Matrix:",sum)
17
+ ini=1
18
+ while(count>=ini):
19
+ if(i==-1 and j==n):
20
+ i=0
21
+ j=n-2
22
+ if(i==-1):
23
+ i=n-1
24
+ if(j==n):
25
+ j=n-n
26
27
+ if(magic[i][j]!=0):
28
+ i=i+1
29
+ j=j-2
30
+ else:
31
+ magic[i][j]=ini
32
+ ini=ini+1
33
+ i=i-1
34
+ j=j+1
35
36
37
+ print(magic[i][j],end=" ")
38
+ print()
39
+print("Magic Square Is only For Odd Numbers")
40
+n=int(input("Enter Square Matrix Size:"))
41
+magic(n)
42
43
44
0 commit comments