mark = array [1..6] of integer ;
(* an array type of integers with 6 elements *)
var
t1mark, t2mark, t3mark, total : mark;
name : array[1..6] of string;
i,(* for loop counter *)
mintotal, min_ndx (* for finding the minimum value of totals *)
: integer;
begin
(* name table *)
name[1]:='John Chan';
name[2]:='Tim Tong';
name[3]:='Regina Lau';
name[4]:='Danny Tsang';
name[5]:='Roy Leung';
name[6]:='Jo Lee';
(* Input marks of the 3 tests for all 6 students *)
for i:=1 to 6 do
begin
writeln ('Enter the three test marks for', name[i], ':');
readln (t1mark[i], t2mark[i],t3mark[i]);
end;
(* Calculate the totals of the 3 tests for all 6 students *)
for i:=1 to 6 do
total[i]:= t1mark[i]+ t2mark[i] + t3mark[i] ;
Writeln;
Writeln('Students failed:');
(* Display names of those students with average mark less than 50 *)
for i:=1 to 6 do
if (total[i]/3)< 50 then
writeln (name[i]);
(* Find the student with the lowest total mark *)
for i := 1 to 6 do
if total[i]/3 < mintotal then
begin
mintotal := total[i];
min_ndx := i ;
end ;
writeln(name[min_ndx],' got the lowest average mark (',mintotal / 3:0:1,')');
readln
end.
更新1:
http://www.uwants.com/viewthread.php?tid=16947809&extra=page%3D2&frombbs=1