Pascal/Turbo Pascal - Ayuda con este array

 
Vista:
sin imagen de perfil

Ayuda con este array

Publicado por matias (1 intervención) el 13/04/2016 17:44:03
Hola, necesito una ayuda con este problema que no me sale:

Dado un archivo de enteros, se pide cargar en un vector V solo los elementos impares y en otro vector W, los pares, ignorando si hubiese algun cero.

gracias.
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

Ayuda con este array

Publicado por ramon (2158 intervenciones) el 15/04/2016 12:59:01
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
{Mira dos tipos de archivos a ver si te ayudan }
 
program numerosarrays;
  uses
     crt;
   type
     numeros = record
             nume : integer;
           end;
    const
       nombrerecor = 'losnume.dat';
       nombretexto = 'elnumer.txt';
   var
     numetexto : integer;
     numerecor : numeros;
     f : file of numeros;
     f1 : text;
     w, v : array[1..100] of integer;
     a1, a2, h, k : integer;
 
    procedure guardarecord(nn : numeros);
    begin
       assign(f,nombrerecor);
    {$I-} reset(f); {$I+}
    if ioresult <> 0 then
    begin
        rewrite(f);
        seek(f,0);
        write(f,nn);
        close(f);
    end
  else
     begin
        seek(f,filesize(f));
        write(f,nn);
        close(f);
     end;
  end;
 
   procedure guardatexto(nn : char);
   begin
       assign(f1,nombretexto);
    {$I-} reset(f1); {$I+}
    if ioresult <> 0 then
    begin
        rewrite(f1);
        write(f1,nn);
        close(f1);
    end
  else
     begin
        append(f1);
        write(f1,nn);
        close(f1);
     end;
  end;
 
  procedure cargarecord;
  var
    cont : longint;
  begin
     h := 1;
     k := 1;
     assign(f,nombrerecor);
    {$I-} reset(f); {$I+}
    if ioresult <> 0 then
    begin
        writeln('   Error De Archivo O No Existe Pulse Una Tecla');
        readkey;
    end
  else
     begin
       for cont := 0 to filesize(f) - 1 do
       begin
           seek(f,cont);
           read(f,numerecor);
           if numerecor.nume mod 2 = 0 then
           begin
           if numerecor.nume > 0 then
           begin
           w[h] := numerecor.nume;
           h := h + 1;
           if h > 100 then
           h := 100;
           end;
           end
         else
            begin
             if numerecor.nume > 0 then
             begin
             v[k] := numerecor.nume;
             k := k + 1;
             if k > 100 then
             k := 100;
             end;
           end;
       end;
       close(f);
     end;
  end;
 
  procedure carhatexto;
  var
    nuch : char;
    nu : integer;
   begin
      assign(f1,nombretexto);
    {$I-} reset(f1); {$I+}
    if ioresult <> 0 then
    begin
       writeln('   Error De Archivo O No Existe Pulse Una Tecla');
       readkey;
    end
  else
     begin
        h := 1;
        k := 1;
        while not eof(f1) do
        begin
           read(f1,nuch);
           nu := ord(nuch) - 48;
           if nu mod 2 = 0 then
           begin
              if nu > 0 then
              begin
              w[h] := nu;
              h := h + 1;
              if h > 100 then
              h := 100;
              end;
           end
        else
           begin
              if nu > 0 then
              begin
              v[k] := nu;
              k := k + 1;
              if k > 100 then
              k := 100;
              end;
           end;
        end;
     end;
   end;
 
   procedure generacionnumeros(tex : boolean);
   var
     mn, elnu : integer;
     dd : char;
   begin
      for elnu := 1 to 50 do
      begin
         mn := random(50) + 1;
         mn := mn + elnu;
         if tex = true then
         begin
         dd := chr(mn + 48);
         guardatexto(dd);
         end
       else
         begin
         numerecor.nume := mn;
         guardarecord(numerecor);
         end;
      end;
   end;
 
  begin
     generacionnumeros(true);
     generacionnumeros(false);
     clrscr;
     carhatexto;
     writeln('   Los Numeros Pares texto');
     for a1 := 1 to h - 1 do
     write(' ',w[a1]);
     writeln;
     writeln;
     writeln('  Los Impares texto');
     for a2 := 1 to k - 1 do
     write(' ',v[a2]);
     cargarecord;
     writeln;
     writeln;
     writeln('   Los Numeros Pares record');
     for a1 := 1 to h - 1 do
     write(' ',w[a1]);
     writeln;
     writeln;
     writeln('  Los Impares record');
     for a2 := 1 to k - 1 do
     write(' ',v[a2]);
     readkey;
     assign(f,nombrerecor);
    {$I-} reset(f); {$I+}
    if ioresult = 0 then
    begin
     close(f);
     erase(f);
    end;
     assign(f1,nombretexto);
    {$I-} reset(f1); {$I+}
    if ioresult = 0 then
    begin
     close(f1);
     erase(f1);
    end;
  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