Pascal/Turbo Pascal - 10 numeros aleatorios en pascal sin repeticion

 
Vista:

10 numeros aleatorios en pascal sin repeticion

Publicado por AndRea Camila (1 intervención) el 31/10/2021 14:23:34
Buen dia, necesito hacer un codigo que me genere 10 numeros al azar sin repeticion, es decir, que me coloque numeros del 0 al 9 en cualquier orden, pero que no se repitan, además no puedo utilizar array

randomize;

s1:='';


for i:=1 to 10 do
begin
x1:=random(10);
str(x1,yaux);
s1:=s1+yaux;
m:=length(s1);

for i:=1 to m do
begin
if (yaux<>s1[i]) then
begin
str(x1,yaux);
s1:=s1+yaux;
m:=length(s1);
end
else
begin
repeat
x1:=random(10);
str(x1,yaux);
m:=length(s1);
until (yaux<>s1[i]);
end;
end;
end;
write(s1);
readkey;

si alguien me pudiera ayyudar, se lo agradecería, porque mi codigo programado no parece leerlo correctamente
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
Val: 36
Ha aumentado su posición en 4 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

10 numeros aleatorios en pascal sin repeticion

Publicado por Armando José (43 intervenciones) el 31/10/2021 21:03:45
(* es hecho en Pascal N-IDE
una aplicacion
muy interesante
realizado por:
Armando Fuenmayor
[email protected]
[email protected]
WhatsApp +58 412-2689131
*)
uses crt;
var
f: text;
n: byte;
i, j: integer;
c0,
c1, c2,
c3, c4,
c5, c6,
c7, c8,
c9 : byte;
begin
clrscr;
c0 := 0;
c1 := 0;
c2 := 0;
c3 := 0;
c4 := 0;
c5 := 0;
c6 := 0;
c7 := 0;
c8 := 0;
c9 := 0;


assign(f, 'numeros.txt');
rewrite(f);
randomize;

j := 0;

while j < 10 do
begin
n := random (10);

if (n = 0) and
(c0 = 0) then
begin
inc(c0);
inc(j);
write(f, n:3)
end;

if (n = 1) and
(c1 = 0) then
begin
inc(c1);
inc(j);
write(f, n:3)
end;

if (n = 2) and
(c2 = 0) then
begin
inc(c2);
inc(j);
write(f, n:3)
end;

if (n = 3) and
(c3 = 0) then
begin
inc(c3);
inc(j);
write(f, n:3)
end;
if (n = 4) and
(c4 = 0) then
begin
inc(c4);
inc(j);
write(f, n:3)
end;
if (n = 5) and
(c5 = 0) then
begin
inc(c5);
inc(j);
write(f, n:3)
end;
if (n = 6) and
(c6 = 0) then
begin
inc(c6);
inc(j);
write(f, n:3)
end;
if (n = 7) and
(c7 = 0) then
begin
inc(c7);
inc(j);
write(f, n:3)
end;
if (n = 8) and
(c8 = 0) then
begin
inc(c8);
inc(j);
write(f, n:3)
end;
if (n = 9) and
(c9 = 0) then
begin
inc(c9);
inc(j);
write(f, n:3)
end;

end;
close (f);

{------------------------------------}

reset (f);
while not eof(f) do
begin
while not eoln (f) do
begin
read(f, n);
write (n:3) ;
end;
readln(f);
writeln;
end;
close(f)
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