Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- rows=int(input('Num of rows: '))
- cols=int(input('Num of cols: '))
- max_el=int(input('What kind of nums i will use for generate matrix? From 1 to: '))
- mas = []
- for i in range(rows):
- mas.append([])
- for j in range(cols):
- r = random.randint(1,max_el)
- mas[i].append(r)
- for i in range(rows):
- print(mas[i], "\n")
- max=0; max_x=0; max_y=0;
- min=max_el; min_x=0; min_y=0;
- for i in range(rows):
- for j in range(cols):
- if mas[i][j]>max:
- max=mas[i][j]
- max_x=j
- max_y=i
- for i in range(rows):
- for j in range(cols):
- if mas[i][j]<min:
- min=mas[i][j]
- min_x=j
- min_y=i
- print("Min num: ", min, "; X: ", min_x, "; Y: ", min_y)
- print("Max num: ", max, "; X: ", max_x, "; Y: ", max_y)
- 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