Pascal/Turbo Pascal - multipliacar 2 arrays

 
Vista:

multipliacar 2 arrays

Publicado por pascal (3 intervenciones) el 26/12/2013 12:18:21
hola necesito saber como puedo hacer para multiplicar 2 arrays para que multipliquen todoss por todos como al hacer una multiplicacion real ej: 123 x 45 : 4x3, 4x2, 4x1, 5x3....
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

multipliacar 2 arrays

Publicado por ramon (2158 intervenciones) el 28/12/2013 19:57:27
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
{Algo así}
 
 program multiplicacion;
  uses
     crt;
  type
     multiplicando = array[1..60] of integer;
     multiplicador = array[1..30] of integer;
     resultados = array[1..30,1..91] of integer;
     suma = array[1..94] of integer;
 
  var
    mul1 : multiplicando;
    mul2 : multiplicador;
    resu : resultados;
    oper : suma;
    rr, z, total, mult1, mult2 : integer;
 
 
  procedure entradanumeros(var m1 : multiplicando; var m2 : multiplicador);
  var
    tec : char;
    i, nu : integer;
  begin
     clrscr;
     i := 1;
     gotoxy(3,1);write('Entre El Multiplicando : ');
     repeat
         tec := readkey;
         if tec in[#48..#57] then
         begin
           nu := ord(tec) - 48;
           m1[i] := nu;
           gotoxy(27 + i,1);write(tec);
           i := i + 1;
           if i > 60 then
           i := 60;
         end;
         if tec = #8 then
         begin
            i := i - 1;
            if i < 1 then
            i := 1;
            m1[i] := 0;
            gotoxy(27 + i,1);write(' ');
         end;
     until tec = #13;
     mult1 := i - 1;
     clrscr;
     i := 1;
     gotoxy(3,1);write('Entre El Multiplicador : ');
     repeat
         tec := readkey;
         if tec in[#48..#57] then
         begin
           nu := ord(tec) - 48;
           m2[i] := nu;
           gotoxy(27 + i,1);write(tec);
           i := i + 1;
           if i > 30 then
           i := 30;
         end;
         if tec = #8 then
         begin
            i := i - 1;
            if i < 1 then
            i := 1;
            m2[i] := 0;
            gotoxy(27 + i,1);write(' ');
         end;
     until tec = #13;
     mult2 := i - 1;
     clrscr;
     for i := 1 to mult1 do
     begin
     gotoxy(15 + i,2);write(m1[i]);
     end;
     for i := 1 to mult2 do
     begin
     gotoxy((15 + (mult1 - mult2)) + i,3);write(m2[i]);
     end;
  end;
 
   procedure multiplica(n1 : multiplicando; n2 : multiplicador;
                                           var r : resultados);
   var
     c1, c2, r1, t1 : integer;
     pp1, x, rest, num : integer;
   begin
      c2 := mult2;
      r1 := mult2;
      rest := 0;
      x := 0;
    repeat
       c1 := mult1;
       t1 := 91 - x;
       repeat
         num := (n1[c1] * n2[c2]) + rest;
         r[r1,t1] := num mod 10;
         num := num div 10;
         rest := num;
         c1 := c1 - 1;
         t1 := t1 - 1;
       until c1 < 1;
       if rest > 0 then
       begin
         r[r1 + 1,t1] := rest;
         t1 := t1 - 1;
         x := 1;
       end;
         rest := 0;
         c2 := c2 - 1;
         r1 := r1 - 1;
         x := x + 1;
    until c2 < 1;
   end;
 
  procedure sumafilas(ss : resultados; var sum : suma);
  var
    y, res, tt, dd, op : integer;
  begin
      dd := 91;
      res := 0;
      y := 1;
      total := 0;
    repeat
      op := 0;
      tt := 1;
      repeat
      op := op + ss[tt,dd];
      tt := tt + 1;
      until tt > mult2;
      op := op + res;
      sum[95 - y] := op mod 10;
      y := y + 1;
      res := 0;
      op := op div 10;
      res := op;
      dd := dd - 1;
    until dd < (91 - ((mult1 + mult2) - 2));
    if res > 0 then
    begin
       sum[95 - y] := res;
       y := y + 1;
    end;
    total := y - 1;
  end;
 
 
  begin
     entradanumeros(mul1,mul2);
     multiplica(mul1, mul2,resu);
     sumafilas(resu,oper);
     for z := 1 to (mult1 + mult2) do
     begin
        gotoxy((15 - mult2) + z,4);write('-');
     end;
     for z := 94 downto (95 - total) do
     begin
     gotoxy((15 + mult1) - rr,5);write(oper[z]);
     rr := rr + 1;
     end;
     readkey;
  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

multipliacar 2 arrays

Publicado por pascal (3 intervenciones) el 02/01/2014 12:09:21
muchas gracias aunque no se si me valdra hay lenguaje que no he dado como gotoxy
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

multipliacar 2 arrays

Publicado por ramon (2158 intervenciones) el 04/01/2014 11:28:24
Mira gotoxy() solo posiciona el texto en pantalla como write o writeln solo que en este caso lo ponemos donde
nosotros queremos y no al inicio de la pantalla puedes cambiarlo no pasa nada x e y son las posiciones en la
pantalla de 1..80 para x y de 1..24 para y.
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