Advertisement
fabis_sparks

YuliaPythonOS

Nov 19th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import random
  2. import math
  3. rows=int(input('Num of rows: '))
  4. cols=int(input('Num of cols: '))
  5. max_el=int(input('What kind of nums i will use for generate matrix? From 1 to: '))
  6. mas = []
  7. for i in range(rows):
  8.     mas.append([])
  9.     for j in range(cols):
  10.         r = random.randint(1,max_el)  
  11.         mas[i].append(r)
  12. for i in range(rows):
  13.     print(mas[i], "\n")
  14. max=0; max_x=0; max_y=0;
  15. min=max_el; min_x=0; min_y=0;
  16. for i in range(rows):
  17.     for j in range(cols):
  18.         if mas[i][j]>max:
  19.             max=mas[i][j]
  20.             max_x=j
  21.             max_y=i
  22. for i in range(rows):
  23.     for j in range(cols):
  24.         if mas[i][j]<min:
  25.             min=mas[i][j]
  26.             min_x=j
  27.             min_y=i
  28.  
  29. print("Min num: ", min, "; X: ", min_x, "; Y: ", min_y)
  30. print("Max num: ", max, "; X: ", max_x, "; Y: ", max_y)
  31. print("distance between max&min elems by X:",math.fabs(max_x-min_x), "; By Y: ", math.fabs(max_y-min_y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement