Pascal/Turbo Pascal - Ejercicio con matriz

 
Vista:
sin imagen de perfil

Ejercicio con matriz

Publicado por Erick (6 intervenciones) el 22/08/2014 04:07:32
Alguna idea que me puedan dar para hacer este programa???
El problema dice así:
Dado un arreglo de n x m elementos. Escriba un programa que determine:

1. El elemento menor y mayor de cada fila y columna
2. La posición del elemento menor y mayor de cada fila y columna
3. El elemento mayor del arreglo
4. La posición del elemento mayor del arreglo
5. El elemento menor de la diagonal principal
6. El elemento mayor y menor de la diagonal secundaria
7. La posición del elemento mayor y menor de la diagonal secundaria
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Ejercicio con matriz

Publicado por ramon (39 intervenciones) el 24/08/2014 14:54:33
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
{A ver si esto te ayuda}
 
program arreglos;
  uses
     crt;
   const
      n = 5;
      m = 5;
   var
     arreglo : array[1..n,1..m] of integer;
     i, t : integer;
 
   procedure rellenaarreglo;
   var
     s, d, nu : integer;
     esis : boolean;
   begin
       randomize;
       t := 1;
       i := 1;
    repeat
       nu := random((n * m) * 2) + 1;
       esis := false;
       for s := 1 to t do
       begin
         for d := 1 to i do
         begin
         if arreglo[s,d] = nu then
         esis := true;
         end;
       end;
       if esis = false then
       begin
         arreglo[t,i] := nu;
         t := t + 1;
         if t > n then
         begin
            i := i + 1;
            t := 1;
         end;
       end;
    until (t * i) > (n * m);
 end;
 
 procedure presentaoriginal;
 begin
    writeln('***** Matriz Original ******');
    writeln;
    for t := 1 to n do
    begin
      write('   ');
      for i := 1 to m do
      begin
         write('  ',arreglo[t,i]);
      end;
      writeln;
      writeln;
    end;
    writeln;
 end;
 
 procedure menor_y_mayor_de_cada_fila_y_columna_y_posicion;
 var
   k, h, fil, col, menor, mallor : integer;
   mn1, mn2, my1, my2 : integer;
 begin
     menor := 1000;
     mallor := 1;
     h := 1;
     k := 1;
     mn1 := 0;
     mn2 := 0;
     my1 := 0;
     my2 := 0;
     presentaoriginal;
     writeln;
     writeln('  El elemento menor y mayor de cada fila y columna y su posicion ');
     writeln;
   repeat
      for col := 1 to m do
      begin
         if arreglo[col,h] < menor then
         begin
         menor := arreglo[col,h];
         mn1 := col;
         mn2 := h;
       end;
         if arreglo[col,h] > mallor then
         begin
         mallor := arreglo[col,h];
         my1 := col;
         my2 := h;
        end;
      end;
     writeln('Columna [',h,'] Menor : posicion [',mn2,'][',mn1,'] ',menor,
     '  Mayor : posicion [',my2,'][',my1,'] ',mallor);
     writeln;
     menor := 1000;
     mallor := 1;
     mn1 := 0;
     mn2 := 0;
     my1 := 0;
     my2 := 0;
     for fil := 1 to n do
      begin
         if arreglo[k,fil] < menor then
         begin
         menor := arreglo[k,fil];
         mn1 := k;
         mn2 := fil;
         end;
         if arreglo[k,fil] > mallor then
         begin
         mallor := arreglo[k,fil];
         my1 := k;
         my2 := fil;
      end;
    end;
      writeln('Filas   [',k,'] Menor : posicion [',mn2,'][',mn1,'] ',
      menor,'  Mayor : posicion [',my2,'][',my1,'] ',mallor);
      writeln;
      h := h + 1;
      k := k + 1;
      menor := 1000;
      mallor := 1;
      mn1 := 0;
      mn2 := 0;
      my1 := 0;
      my2 := 0;
    until (h * k) > (n * m);
     readkey;
 end;
 
 procedure Elemento_mayor_del_arreglo_y_posicion;
 var
   p1, p2, x, y, may : integer;
  begin
     may := 0;
   for y := 1 to m do
     for x := 1 to n do
      if arreglo[x,y] > may then
     begin
         may := arreglo[x,y];
         p1 := y;
         p2 := x;
     end;
     presentaoriginal;
     writeln;
     writeln('   El elemento mayor del arreglo y posicion');
     writeln;
     writeln('   El Elemento Mayor De La Matriz Y posicion Es : [',p1,'][',p2,'] ',may);
     readkey;
  end;
 
  procedure Elemento_menor_de_la_diagonal_principal;
  var
     va, d1, d2 : integer;
   begin
     d2 := 1;
     va := 1000;
     for d1 := 1 to m do
     begin
     if arreglo[d2,d1] < va then
     va := arreglo[d2,d1];
     d2 := d2 + 1;
     end;
     presentaoriginal;
     writeln;
     writeln('  El elemento menor de la diagonal principal');
     writeln;
     writeln('El Elemento Menor DeLa Diagonal Principal Es : ',va);
     readkey;
   end;
 
 
  procedure Elemento_mayor_y_menor_de_la_diagonal_secundaria_y_posicion;
  var
    pos1, pos2, pos3, pos4, nm1, nm2, nm3, nm4, menor, mayor : integer;
   begin
     nm1 := 2;
     pos1 := 0;
     pos2 := 0;
     pos3 := 0;
     pos4 := 0;
     mayor := 0;
     menor := 1000;
     for nm2 := 1 to m do
     begin
     if menor > arreglo[nm2,nm1] then
     begin
     menor := arreglo[nm2,nm1];
     pos1 := nm2;
     pos2 := nm1;
     end;
     if mayor < arreglo[nm2,nm1] then
     begin
        mayor := arreglo[nm2,nm1];
        pos3 := nm2;
        pos4 := nm1;
     end;
      nm1 := nm1 + 1;
    end;
    presentaoriginal;
    writeln;
    writeln('  Las posiciones del elemento mayor y menor de la diagonal secundaria ');
    writeln;
    writeln('El Menor Y Posicion Es [',pos2,'][',pos1,'] ',menor);
    writeln;
    writeln('El Mayor Y Posicion Es [',pos4,'][',pos3,'] ',mayor);
    writeln;
    readkey;
   end;
 
 procedure menu;
 var
    salir : boolean;
    tec : char;
  begin
     salir := false;
     rellenaarreglo;
   repeat
    clrscr;
    writeln('   ***** Menu Jeneral *****');
    writeln;
    writeln(' 1 = Elemento menor y mayor de cada fila y columna y posicion');
    writeln(' 2 = Elemento mayor del arreglo');
    writeln(' 3 = Elemento menor de la diagonal principal');
    writeln(' 4 = Elemento mayor y menor de la diagonal secundaria');
    writeln(' 5 = Salir');
    writeln;
    writeln('   <<<<<<< Elija Opcion >>>>>>>>>');
    repeat
       tec := readkey;
    until tec in['1','2','3','4','5'];
    clrscr;
    case tec of
 '1' : menor_y_mayor_de_cada_fila_y_columna_y_posicion;
 '2' : Elemento_mayor_del_arreglo_y_posicion;
 '3' : Elemento_menor_de_la_diagonal_principal;
 '4' : Elemento_mayor_y_menor_de_la_diagonal_secundaria_y_posicion;
 '5' : salir := true;
   end;
   until salir = true;
  end;
 
 
 
 begin
    menu;
 end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar