Pascal/Turbo Pascal - programas con arrays

 
Vista:

programas con arrays

Publicado por Jube (10 intervenciones) el 30/10/2012 19:06:05
2. Implementa un programa en Pascal que
- Lea una matriz M de dimensión 4x4 y un número n (entre 1 y 4).
- Obtenga la submatriz S 3x3 que resulta al quitar a la matriz de entrada la columna 1 y la fila
correspondiente al número n leído.
- Muestre la submatriz obtenida.
Ejemplo
M
3 12 31 s
1" -6 :4 -4
12 3 -5 17
21 64 92 1
Número leído 3
Submatriz S obtenida
12 31 S
-6 -4
64 92 1




3. Diseña un programa que lea una tabla T(2xn) cuya primera fila esté formada por enteros positivos y la
segunda por enteros entre 0 y n (ambos inclusive). A partir de esta tabla se deberá construir una matriz
M(nxn) donde aparecerán los enteros de la primera fila de T tantas veces como indique el correspondiente
valor de la segunda fila. Las posiciones no ocupadas se rellenarán con ceros.
Ejemplo: con n=5
T
6 9 4 3 1
1 2 4 2 5
Matriz M obtenida:
6 0 0 0 0
9 9 0 0 0
4 4 4 4 0
3 3 0 0 0
1 1 1 1 1
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

programas con arrays

Publicado por ramon (2158 intervenciones) el 31/10/2012 21:15:19
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
{A ver si esto te ayuda }
 
program matriz;
 uses
   crt;
   const
      num = 5;
   type
     matriz1 = array[1..4,1..4] of integer;
     susmatriz = array[1..3,1..3] of integer;
     tabla = array[1..num,1..num] of integer;
     tabla2 = array[1..2,1..num] of integer;
 
  var
    m : matriz1;
    s : susmatriz;
    r, k, n : integer;
    t1 : tabla2;
    mt : tabla;
 
  procedure tratamatriz;
  var
    t, y, nn : integer;
  begin
     y := 1;
     repeat
         t := 1;
         repeat
         clrscr;
         write('Entre N§ l = ',t,' | c = ',y,' : ');
         readln(m[t,y]);
         t := t + 1;
         until t > 4;
         y := y + 1;
     until y > 4;
     clrscr;
   repeat
     write('  Entre N§ 1 al 4 : ');
     readln(nn);
  until nn in[1,2,3,4];
  for y := 1 to 4 do
  begin
    for t := 1 to 4 do
    begin
    write('  ',m[t,y]);
    end;
    writeln;
  end;
  for y := 1 to 3 do
    for n := 1 to 3 do
    s[y,n] := 0;
  writeln;
  n := 1;
  r := 1;
     for y := 2 to 4 do
     begin
       for t := 1 to 4 do
       if t <> nn then
       begin
       s[r,n] := m[y,t];
       n := n + 1;
      end;
      n := 1;
      r := r + 1;
     end;
  end;
 
  procedure trataypresentamatriz;
  begin
     clrscr;
      tratamatriz;
      for n := 1 to 3 do
      begin
        for k := 1 to 3 do
        begin
        write('  ',s[k,n]);
        end;
        writeln;
      end;
      readln;
  end;
 
  procedure entradastabla;
  var
    x1, vv, xx, cc, nr, tb : integer;
  begin
     nr := 1;
  repeat
     tb := 1;
   repeat
   clrscr;
   if nr = 1 then
   write('  Entre N§ entero : ')
  else
   write('  Entre N§ 0 a ',num,' : ');
   readln(t1[nr,tb]);
   if (nr = 2) and (t1[nr,tb] > num) then
   tb := tb - 1
  else
   tb := tb + 1;
   until tb > num;
   nr := nr + 1;
   until nr > 2;
   cc := 0;
   clrscr;
   for nr := 1 to num do
   begin
      cc := t1[1,nr];
      xx := t1[2,nr];
       for x1 := 1 to xx do
       write(' ',cc);
         if xx < num then
          for x1 := xx to num - 1 do
          write(' ','0');
         writeln;
      end;
    end;
 
   procedure menu;
   var
     sal : boolean;
     tr : char;
   begin
      sal := false;
    repeat
       clrscr;
       writeln('**** Menu General ****');
       writeln;
       writeln('  [1] = que lea una matriz M de dimension 4x4');
       writeln('  [2] = que lea una tabla T(2xn)');
       writeln('  [3] = salir');
       writeln;
       writeln('<<< Elija Opcion >>>');
       repeat
          tr := readkey;
       until tr in['1','2','3'];
   case tr of
 '1' : begin clrscr; trataypresentamatriz; end;
 '2' : begin clrscr; entradastabla; end;
 '3' : sal := true;
   end;
     until sal = true;
   end;
 
 
 
  begin
     clrscr;
     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
1
Comentar