0

The array k*k is given. Replace the elements of the main diagonal with the elements of the additional diagonal.

Python

9th Apr 2022, 12:08 AM
Gulnur
5 Respostas
+ 2
Gulnur , can you please enlighten us what the definition of *main diaginal* and *additional diagonal* is. a sample would be nice. thanks!
9th Apr 2022, 6:52 AM
Lothar
Lothar - avatar
+ 2
for n in range(k): arr[n][n]=arr[n][-1-n]
9th Apr 2022, 7:46 AM
Oma Falk
Oma Falk - avatar
+ 2
Oma Falk Now it was clear. Thank you very much🤭
9th Apr 2022, 8:22 AM
Gulnur
+ 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()
9th Apr 2022, 7:27 AM
Gulnur
0
k[1][1] = j[1] k[2][2] = j[2]
9th Apr 2022, 1:45 AM
HungryTradie
HungryTradie - avatar