Board index » delphi » Need HELP FINISHING PROGRAM (posted program) PASCAL

Need HELP FINISHING PROGRAM (posted program) PASCAL

Can someone please help me finish this program.  I need it to sort the
numbers instead of printing them in random order.  If you can help me
E-MAIL me at
SUPER...@aol.com

Thanks

Program ch14 (input, output);
{Produces a list of 1000 numbers without duplicates and lists them in
order}

uses crt, printer;
label 10;
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;
begin
  for x := 1 to 999 do
    for y:=x+ 1 to 1000 do
      if num [x] >num[y] then;
      begin
         z := num[x];
         num[x] := num[y];
         num[y] := z;
      end;
  end;

begin
   clrscr;
   assign (outfile, 'c:c14.txt');
   rewrite (outfile);
   randomize;
   for a:=1 to 2000 do
   order [a] := 0;
   for x:= 1 to 1000 do
      begin
        10:pnum:=random(2000) + 1;
        if order [pnum] = 0 then
           num [x] := pnum else
           goto 10;
        order[pnum] := 1;
      end;
   sort;
   for b:= 1 to 1000 do
       write (outfile, num [z]);
   for b:= 1 to 1000 do
      if b mod 10=0 then
      writeln (lst, num[b]:8)else
      writeln(lst, num[b]:8);
   end.

 

Re:Need HELP FINISHING PROGRAM (posted program) PASCAL


Quote
Robert Grossman <r...@ix.netcom.com> wrote:
>< stuff deleted >
>> >procedure sort;
>> >begin
>> >   for x := 1 to 999 do
>> >     for y := x + 1 to 1000 do
>> >       if num[x] > num[y] then; { <--< semi-colon ended }
>> >       begin                    {      the IF statement }
>> >          z := num[x];
>> >          num[x] := num[y];
>> >          num[y] := z;
>> >       end;
>> >end;

Then you may wish to go QuickSort, though....much more efficient on
everything, except almost sorted data.

Glenn Grotzinger
mailto:ggr...@2sprint.net
MOD and S3M user extraordinaire.
Writer of TP tutorial.  All released parts findable at:
ftp://garbo.uwasa.fi/pc/turbopas/tptutr11.zip

Other Threads