Advertisement
FaDaQ

Сумма положительных элементов главной диагонали матрицы

Apr 30th, 2022
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. import random
  2.  
  3. arr = [
  4.     [random.randint(-99, 99) for i in range(10)] for j in range(10)
  5. ]
  6.  
  7. j = 0
  8. sum = 0
  9.  
  10.  
  11. for i in range(len(arr)):
  12.     if arr[i][j] >= 0:
  13.         sum += arr[i][j]
  14.     j += 1
  15. print(f"Сумма положительных чисел главной диагонали матрицы: {sum}\n")
  16.  
  17. print("Сама матрица:")
  18. for i in range(len(arr)):
  19.     for j in range(len(arr[i])):
  20.         print(arr[i][j], end=" ")
  21.     print()
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement