Pascal/Turbo Pascal - Me podrían ayudar?

 
Vista:
sin imagen de perfil

Me podrían ayudar?

Publicado por Allen (8 intervenciones) el 02/04/2014 02:11:54
Buenas, quisiera que me ayudaran a hacer este programa utilizando vectores si no es mucha molestia:

Diseñar un programa que lea 25 números enteros y que
a) determine si dos de estos enteros (cualesquiera que estos sean), sumen 15, visualizar las localidades donde se encuentran.
b) encuentre el segundo número más pequeño y el segundo más grande, visualizar el número y su localidad.
c) encuentre el número par más grande o que visualice NO HAY UN NUMERO PAR.
d) Visualizar el número de pares y la de impares..


Gracias, espero y me puedan ayudar.
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
sin imagen de perfil

Me podrían ayudar?

Publicado por Diego (98 intervenciones) el 02/04/2014 03:03:54
Buenas noches loq ue tenés que hacer es declarar un vextor y luego sobre este hacer una lectura dentro de un for para que se completen todos los elementos del vector con algún dato válido, después, como no se indica que haya algún orden en ese vector hay que recorrerlo completamente.
a) tenés que hacer un for anidado (osea un for dentro de otro) va a preguntar ¿la posicion [1 ] + posicion [2] = 15? si es sí guardás las posiciones de ambos y luego infomás esas posiciones; el enunciado no dice nada de mostrar todos los que sumen 15, pero esto está pensado para mostrar todos; en caos que solo tenga que mostrar uno; tendría que ser dentro de un while para avitar iterar de más;
en todo caso si la posicion [1 ] + posicion [2] <> 15 entonces avanzas y preguntás ¿la posicion [1 ] + posicion [3] = 15? y sí hasta la posicion 25: ¿la posicion [1 ] + posicion [25] = 15?
luego de llegar al final empezas a preguntar ¿la posicion [2 ] + posicion [3] = 15? así hasta llegar a la 24 con la 25 ¿la posicion [24] + posicion [25] = 15?

esto se debe a la propiedad conmutaiva de la suma a+b = b+a ; como solo involucra dos numeros enteros si a + b no es lo que querés entonces b+a tampoco lo será;

tengo sueño quizás mañana continue con los demás o si tenés alguna duda. planteala.
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
sin imagen de perfil

Me podrían ayudar?

Publicado por Allen (8 intervenciones) el 02/04/2014 03:31:17
Gracias por responder, bueno, ya entiendo la parte a), aunque si seria un poco tedioso hacer todas esas operaciones, pero sabes necesitaría ver el código (ya de todo) para poder entenderle un poco mas, es que aun estoy un poco verde en esto.
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

Me podrían ayudar?

Publicado por ramon (2158 intervenciones) el 03/04/2014 00:02:21
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
{A ver si esto sirve de ayuda}
 
 program numeros;
 uses
    crt;
  const
     nl = 25;
 
  var
    num : array[1..nl] of integer;
    i : integer;
 
   procedure entradanumeros(var n : array of integer);
   var
      nut : integer;
      cuen : integer;
   begin
      randomize;
      for cuen := 1 to nl do
      begin
          nut := random(15) + 1;
          num[cuen] := nut;
      end;
   end;
 
   procedure suman15(dd : array of integer);
   var
     p1, p2, c1, c2 : integer;
               resu : integer;
                sal : boolean;
   begin
      resu := 0;
      c1 := 1;
      sal := false;
   repeat
        c2 := c1 + 1;
         resu := 0;
         repeat
         resu := dd[c1] + dd[c2];
         if resu = 15 then
         begin
         p1 := c1;
         p2 := c2;
         sal := true;
         end;
         if sal = false then
         c2 := c2 + 1;
         until (c2 > nl) or (sal = true);
         if sal = false then
         c1 := c1 + 1;
       until (c1 > nl) or (sal = true);
      if (dd[p2] + dd[p1]) = 15 then
      begin
      writeln('  Numeros    ',dd[p1],' Y ',dd[p2]);
      writeln('  Posiciones ',p1,' Y ',p2);
      end;
    end;
 
   procedure numeromaxminseg(g : array of integer);
   var
     tmax, tmin : integer;
     posx, posy : integer;
     b1, b2, i : integer;
     temp : array[1..nl] of integer;
     par : integer;
   begin
      for i := 1 to nl do
      temp[i] := g[i];
     for b1 := 1 to nl do
       for b2 := nl downto b1 + 1 do
       if temp[b1] > temp[b2] then
       begin
          i := temp[b1];
          temp[b1] := temp[b2];
          temp[b2] := i;
       end;
        tmin := temp[2];
        if tmin = temp[1] then
        tmin := temp[3];
        tmax := temp[nl - 1];
        if tmax = temp[nl] then
        tmax := temp[nl - 2];
        for i := 1 to nl do
        if g[i] = tmin then
        begin
        if g[i + 1] = tmin then
        posy := i + 1
      else
        posy := i;
        break;
        end;
        for i := 1 to nl do
        if g[i] = tmax then
        begin
        if g[i + 1] = tmax then
        posx := i + 1
      else
        posx := i;
        break;
        end;
        writeln;
        writeln(' Numero Segundo Mayor     = ',tmax,'  Posicion = ',posx);
        writeln(' Numero Segundo Menor     = ',tmin,'  Posicion = ',posy);
        writeln;
        par := 0;
        for i := nl downto 1 do
        if g[i] mod 2 = 0 then
        begin
           par := g[i];
           break;
        end;
        writeln;
        if par = 0 then
        writeln(' NO HAY UN NUMERO PAR ')
     else
        writeln(' Numero Par Mas Grande Es = ',par);
     writeln;
     write('   Los Pares Son : ');
     for i := 1 to nl do
     if g[i] mod 2 = 0 then
     write(' ',g[i]);
     writeln;
     write(' Los Impares Son : ');
     for i := 1 to nl do
     if g[i] mod 2 <> 0 then
     write(' ',g[i]);
     writeln;
     writeln;
     writeln(' El Array Cargo ');
     for i := 1 to nl do
     write(' ',g[i]);
   end;
 
   begin
       clrscr;
       entradanumeros(num);
       suman15(num);
       numeromaxminseg(num);
       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