Last active
November 24, 2018 19:01
-
-
Save fcschmidt/354d1a7e5bda8ce1c394f33e9e32c768 to your computer and use it in GitHub Desktop.
Soma valores das duas diagonais principais.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
def diagonal_principal(m): | |
ac = 0 | |
m1 = [] | |
while ac <= len(m) - 1: | |
vet = m[ac] | |
vet[ac] += 1 | |
ac += 1 | |
m1.append(vet) | |
return m1 | |
def diagonal_secundaria(m): | |
dec = len(m) - 1 | |
aux = 0 | |
m2 = [] | |
while dec >= 0: | |
vet = m[aux] | |
vet[dec] += 1 | |
m2.append(vet) | |
dec -= 1 | |
aux += 1 | |
return m2 | |
if __name__ == '__main__': | |
matrix = [ | |
[0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0] | |
] | |
diagonal_principal(matrix) | |
s = diagonal_secundaria(matrix) | |
for i in s: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment