Skip to content

Instantly share code, notes, and snippets.

@fcschmidt
Last active November 24, 2018 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcschmidt/354d1a7e5bda8ce1c394f33e9e32c768 to your computer and use it in GitHub Desktop.
Save fcschmidt/354d1a7e5bda8ce1c394f33e9e32c768 to your computer and use it in GitHub Desktop.
Soma valores das duas diagonais principais.
#!/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