{F.5AC Winnie Leung (21)} Program MarkSix; uses wincrt; Var N:array[1..7] of integer; Table:array[1..47] of integer; RN,temp,i,j,k,pass,flag:integer; Begin (* Initialize arrays Table[] & N[] *) for i:=1 to 47 do Table[i]:=0 ; for i:=1 to 6 do N[i]:=0; (* Pointer points at N[1] *) j:=1; (* Generate a random number storing at RN *) Randomize; RN:=random(47)+1; repeat (* Elements in Table[] are zero, execution is allowed through the While loop *) While Table[RN]=0 do begin (* The random number is assigned to N[] according to the N[] pointer *) N[j]:=RN; (* Table[] pointer points at RN & Table[] is set to 1 *) Table[RN]:=1; (* N[] Pointer is incremented by 1 *) j:=j+1; end; (* Generate a random number if the N[] pointer points below 8 If the number has been generated, execution will not be allowed to enter the While loop*) Randomize; RN:=random(47)+1 until j>7; (* Bubble sort to sort first 6 numbers of N[], there are 5 passes for 6 numbers *) For pass:=1 to 5 do begin Flag:=0; For k:=1 to 6-pass do begin if N[k]>N[k+1] then begin temp:=N[k+1]; N[k+1]:=N[k]; N[k]:=temp; Flag:=1 end; (* Check the flag at the lowest position of each pass. If flag=0 there is no swap in that pass, all elments has been sorted, then output the sorted numbers *) if k=6-pass then begin if flag=0 then begin writeln('The 6 Mark Six numbers in ascending order : '); For i:=1 to 6 do write(N[i],' '); (* Element at N[7] has not been sorted and this is the extra drawing number *) Writeln; Writeln('The extra drawing number is ',N[7]); (* After outputting the results set conditions to end the double loops *) pass:=5;k:=1; end end; end end end.