Tipo de dato para numeros enteros grandes.
Publicado por Dendi 8 (5 intervenciones) el 10/03/2017 22:01:04
Hola, resulta que quise hacer un programa como para "jugar" a una especie de juego matematico que se llama conjetura de Collatz, el juego es facil: si el numero es par, se lo divide por dos, si el numero es impar, se lo multiplica por 3 y se le suma uno, resulta que todos los numeros van al uno. y solamente se puede hacer con enteros, mi pregunta es. ¿Existe algun tipo de dato en pascal que sea para numeros enteros mas grande que los que permite la variable integer? Les comparto mi código por si lo quieren usar.
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
program Collatz;
uses crt;
var
num,numant: integer;
aux,c,posx,posy:integer;
rta:Char;
b: boolean;
procedure CUENTADIGITOS;
begin
aux:=1;
c:=0;
repeat
c:=c+1;
aux:=aux*10
until abs(num)<aux;
end;
procedure COLOREA;
begin
if num mod 2 = 0 then
textcolor (6) else textcolor (12);
end;
Procedure PANTALLA;
begin
if Numant mod 2 = 0 then begin
posy := posy +1;
colorea;
gotoxy (posx,posy);
write (num);
end
else
begin
if posx < 18 then
begin
colorea;
b := true;
posy := posy +1;
posx := 18;
gotoxy (18,posy);
write (Num);
exit;
end;
if posx > 60 then
begin
colorea;
b := false;
posy := posy +1;
posx := 60;
gotoxy (60,posy);
write (num);
exit;
end;
if b = true then
begin
colorea;
gotoxy (posx + c, posy);
write (' > ',num);
posx := posx +c +3;
end
else
begin
numant := num;
cuentadigitos;
colorea;
gotoxy (posx -c -3,posy);
write (num,' < ');
posx := posx -c -3;
end;
end;
end;
// programa //
begin
repeat
b:= true;
clrscr;
numant := 0;
posx := 18; posy := 1;
textcolor (11);
write (' Ingrese numero a analizar segun Conjetura de Collatz: '); readln (num); clrscr;
if num mod 2 = 0 then
begin
textcolor (6);
end
else begin
textcolor (12);
end;
gotoxy (posx,posy);
write (num, '>');
while num <> 1 do
begin
numant := num;
CUENTADIGITOS;
if num mod 2 = 0 then
begin
textcolor (6); num := num div 2 ;
end
else
begin
textcolor (12); num := (num *3) +1 ;
end;
PANTALLA;
end;
gotoxy (1, posy +3);
textcolor (11);
writeln ('desea seguir? S/N');
repeat readln (rta) until (rta='s') or (rta='n');
until rta = 'N'
end.
Valora esta pregunta
0