0
The array k*k is given. Replace the elements of the main diagonal with the elements of the additional diagonal.
5 Réponses
+ 2
Gulnur ,
can you please enlighten us what the definition of *main diaginal* and *additional diagonal* is. a sample would be nice.
thanks!
+ 2
for n in range(k):
arr[n][n]=arr[n][-1-n]
+ 2
Oma Falk Now it was clear. Thank you very much🤭
+ 1
Lothar the main Diagonal is a[i] [i], and I didn't understand which additional diagonal is which. But I tried writing code, thinking a[j][j]. Please check if this is correct.
from random import random
k=4
a=[]
for i in range(k):
z=[]
for j in range(k):
n=int(random()*100)
z.append(n)
print("%4d"%n,end='')
print()
a.append(z)
print()
for i in range(k):
for j in range(k):
if i==j:
b=a[i][j]
a[i][j]=a[i][k-1-j]
a[i][k-1-j]=b
for i in range(k):
for j in range(k):
print("%4d"%a[i][j],end='')
print()
0
k[1][1] = j[1]
k[2][2] = j[2]