NEED HELP FINISHING PROGRAM

On 18 Apr 1996 21:26:37 -0400 you wrote:

Quote
>I need this to print the numbers out in ascending order instead of random
>order.  I am having trouble figuring it out.  If you can help me it will
>be appreciated.

>{Produces a list of 1000 numbers without duplicates and lists them in
>order}

[...]
>var
>  pnum, a, b, x, y, z: integer;
>  num: array [1..1000] of integer;
>  order: array [1..2000] of integer;
>  outfile: file of integer;

[...]

procedure 'sort' is useless.
if you have to print only sorted numbers - array 'num' is useless too.
------------------------------------------------------------------------

const
MaxNum = 2000;
GenNum = 1000;

var
Numbers: array[ 1..GenNum ] of integer;
UsedNum: array[ 1..MaxNum ] of boolean;
i, j, p: integer;

begin
for i := 1 to MaxNum do UsedNum[ i ] := false;

Randomize;
for i := 1 to GenNum do
begin
repeat p := Random( MaxNum ) + 1
until not UsedNum[ p ];
Numbers[ i ] := p;
UsedNum[ p ] := true
end;

for i := 1 to GenNum do
if i mod 10 = 0
then WriteLn( Numbers[ i ] : 5 )
else Write  ( Numbers[ i ] : 5 );
WriteLn;

j := 0;
for i := 1 to MaxNum do
if UsedNum[ i ] then
begin
j := j + 1;
if j mod 10 = 0
then WriteLn( i : 5 )
else Write  ( i : 5 )
end;
WriteLn
end;

-----------------------------------------------------------------------
The code above is not tested nor debugged, but is fairly simple.

Grego

--

/------------------------------------------------------------------
Gregorio Kus    Gr...@RMnet.it                 Gr...@{*word*104}space.org
ROMA, Italy     http://www.RMnet.it/~grego     Gr...@FreeNet.hut.fi