SHARE
TWEET

Matrix max

-_Neo_- Mar 26th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Mar 12 11:48:50 2019
  4.  
  5. Matrizes
  6. """
  7.  
  8. from random import *
  9. from math import *
  10. def gera_vetor(x): # "x" é a dimensão do vetor.
  11.     x = int(x)
  12.     i = 0
  13.     vetor=[0]*x
  14.     inter = randint(1,(10*x))
  15.     while i < len(vetor):
  16.         vetor[i] = randint(-inter,inter)
  17.         i = i + 1
  18.     return vetor
  19.  
  20. def max_lista(L):
  21.     t = 0
  22.     maximo = L[0]
  23.     while t < len(L):
  24.         if maximo <= L[t]:
  25.             maximo = L[t]
  26.         t = t + 1
  27.     return maximo
  28.  
  29. def max_matrix(M):
  30.     t = 0
  31.     Max = max_lista(M[0])
  32.     while t < len(M):
  33.         if Max <= max_lista(M[t]):
  34.             Max = max_lista(M[t])
  35.         t += 1
  36.     return Max
  37.  
  38. a = gera_vetor(3)
  39. b = gera_vetor(3)
  40. c = gera_vetor(3)
  41. matriz = [a,b,c]
  42. print('A matriz em questão é: \n{0}\n{1}\n{2}'.format(a,b,c))
  43. print('Elementos máximos por linha, respectivamente: \n{0}, {1} e {2}'.format(max_lista(a),max_lista(b),max_lista(c)))
  44. print('O elemento máximo é: {}'.format(max_matrix(matriz)))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top