(* program assumes only integers will be input *) (* also uses statically created array *) program some_guys_homework; const MAX_ARRAY_SIZE = 100; var count,nr_nums,largest,smallest,first_twelve,last_twelve:integer; a :array[1..MAX_ARRAY_SIZE] of integer; found_one : boolean; begin (* initialise variables *) first_twelve:=0; last_twelve:=0; largest:=0; smallest:=0; found_one:=false; (* Get the number of numbers from the user *) write('How many numbers ? '); readln(nr_nums); (* check that the user doesn't want more numbers than we can handle*) if nr_nums > MAX_ARRAY_SIZE then begin writeln('sorry - thats just too many numbers'); writeln('Try again with less than ',MAX_ARRAY_SIZE); exit; end; (* start input loop *) write('enter number : '); readln(a[1]); smallest:=a[1]; largest:=a[1]; for count := 2 to nr_nums do begin write('enter number : '); readln(a[count]); (* check for new largest number *) if (a[count] > largest) then largest :=a[count]; (* check for new smallest number *) if (a[count] < smallest) then smallest:=a[count]; end; (* finished getting in the numbers *) (* Time to check for twelves *) for count := 1 to nr_nums do begin if a[count]=12 then begin if found_one then (* we've already found at least one twelve *) begin last_twelve:=count; end else (* this is the first twelve we've found *) begin first_twelve:=count; last_twelve:=count; found_one:=true; end; end; end; (* finished with the twelves *) (* output the array *) for count := 1 to nr_nums do begin writeln(' Array[',count,'] = ',a[count]); end; (* output the largest and smallest numbers *) writeln('The largest number was : ',largest); writeln('The smallest number was : ',smallest); (* output the twelves *) if found_one = false then writeln('No twelves found in array') else begin writeln('First twelve found at ',first_twelve); writeln('Last twelve found at ',last_twelve); end; writeln('Finished.'); end.