Pascal/Turbo Pascal - Cifra i-esima

 
Vista:
sin imagen de perfil

Cifra i-esima

Publicado por ayudaPascal (2 intervenciones) el 16/11/2014 21:07:12
Hola buenas como se haría esto :



Cifra i-ésima. Esta opción solicitará un número entero positivo (n) y la posición de la cifra que quiere extraer. Esa posición ha de ser válida (es decir, debe ser un número comprendido entre 0 y el número de cifras de n menos uno). Llamará a un subprograma que reciba estos dos números enteros y devuelva la cifra correspondiente usando recursión. El programa principal mostrará dicha cifra
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

Cifra i-esima

Publicado por ramon (2158 intervenciones) el 19/11/2014 00:37: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
{Algo asi}
 
program cifra;
  uses
     crt;
  var
    num : string[20];
    mmn, p, cont, i : integer;
 
  function longnum(n1 : string) : integer;
  begin
      longnum := 0;
      longnum := ord(n1[0]);
   end;
 
  procedure entra_numero;
  var
    tt : char;
    aux : string[20];
  begin
     write('   Entre Numero                   : ');
     i := 1;
     repeat
        tt := readkey;
        if tt in['1'..'9','0'] then
        begin
          num[i] := tt;
          num[0] := chr(i);
          write(num[i]);
          i := i + 1;
        end;
      if tt = #8 then
      begin
        i := i - 1;
        if i < 1 then
        i := 1;
        num[i] := ' ';
        clrscr;
        write('   Entre Numero                   : ');
        aux := copy(num,1,i - 1);
        num := aux;
        write(num);
      end;
     until tt = #13;
     writeln;
     write('   Entre posicion Cifra A Estraer : ');
     readln(cont);
     if cont > longnum(num) then
     entra_numero;
  end;
 
  procedure i_esimo(d : string; hh : integer);
  begin
    if hh > 0 then
    begin
     if p > 1 then
     begin
        mmn := (ord(d[p - 1]) - 48) + (ord(d[p - 2]) - 48);
        p := p + 1;
     end
   else
      begin
         mmn := ord(d[p]) - 48;
         p := p + 1;
      end;
      i_esimo(d,hh - 1);
   end;
 end;
 
  begin
     clrscr;
     entra_numero;
     p := 1;
     mmn := 0;
     writeln;
     writeln('  Numero = ',num,'  Posicion = ',cont);
     i_esimo(num,cont);
     writeln('   El i_esimo Es = ',mmn);
     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