Calcula los valores mayor y menor de una matriz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | {-Victor De la Rocha} {-Algoritmia@groups.msn.com} {-www.myalgorithm.com} {PROGRAMA 5: Muesta los valores mayor y menor de una matriz} uses crt; const max=100; type matriz=array[1..max,1..max] of integer; vector=array[1..max] of integer; var valor,veces:integer; filas,cols,cont1,cont2,cont3:integer; limite,t1,t2:integer; arreglo:matriz; temp:vector; begin randomize; CLrScr; Write('Filas: ');Readln(filas); Write('Columnas: ');Readln(cols); for cont1:=1 to filas do begin for cont2:=1 to cols do begin arreglo[cont1,cont2]:=random(100); writeln('Matriz[',cont1,'][',cont2,'] = ',arreglo[cont1,cont2]); end; end; {introdusco los valores en un vector, para ordenarlos} writeln; limite:=filas*cols; cont3:=0; for cont1:=1 to filas do begin for cont2:=1 to cols do begin cont3:=cont3+1; temp[cont3]:=arreglo[cont1,cont2]; end; end; {ordeno el vector} for cont1:=(filas*cols) downto 1 do begin for cont2:=1 to cont1 do begin if temp[cont2]>temp[cont1] then begin t1:=temp[cont1]; t2:=temp[cont2]; temp[cont1]:=t2; temp[cont2]:=t1; end; end; end; {Regreso los valores a la matriz} cont3:=0; for cont1:=1 to filas do begin for cont2:=1 to cols do begin cont3:=cont3+1; arreglo[cont1,cont2]:=temp[cont3]; end; end; {imprimo el valor mayor y menor} writeln('Menor: ',arreglo[1,1]); writeln('Mayor: ',arreglo[filas,cols]); Readkey;end.{programa} |
Filas: 6
Columnas: 5
Matriz[1][1] = 65
Matriz[1][2] = 90
Matriz[1][3] = 18
Matriz[1][4] = 45
Matriz[1][5] = 18
Matriz[2][1] = 57
Matriz[2][2] = 34
Matriz[2][3] = 6
Matriz[2][4] = 78
Matriz[2][5] = 84
Matriz[3][1] = 86
Matriz[3][2] = 63
Matriz[3][3] = 91
Matriz[3][4] = 80
Matriz[3][5] = 96
Matriz[4][1] = 0
Matriz[4][2] = 52
Matriz[4][3] = 4
Matriz[4][4] = 34
Matriz[4][5] = 53
Matriz[5][1] = 11
Matriz[5][2] = 68
Matriz[5][3] = 24
Matriz[5][4] = 3
Matriz[5][5] = 64
Matriz[6][1] = 28
Matriz[6][2] = 38
Matriz[6][3] = 89
Matriz[6][4] = 56
Matriz[6][5] = 95
El mayor es: 95
El menor es: 0