Var k, m, t : integer; Dat: array[1..10] of integer; Begin Dat[1] := 36; Dat[2] := 50; Dat[3] := 23; Dat[4] :=41; Dat[5] := 27; Dat[6] := 22; Dat[7] := 59; Dat[8] := 12; Dat[9] := 65; Dat[10] := 35; m := 0; for k := 1 to 10 do if Dat[k] >m then begin m := Dat[k]; t := k end; writeln(k) End.
The program is meant to find the maximum value in the array Dat and the index at which it occurs.
The correct syntax for the comparison statement is "if Dat[k] > m then" instead of "if Dat[k] >m then". The correct code should be:
Var k, m, t : integer;
Dat: array[1..10] of integer;
Begin Dat[1] := 36; Dat[2] := 50; Dat[3] := 23; Dat[4] :=41; Dat[5] := 27; Dat[6] := 22; Dat[7] := 59; Dat[8] := 12; Dat[9] := 65; Dat[10] := 35;
m := 0;
for k := 1 to 10 do if Dat[k] > m then
begin
m := Dat[k]; t := k end;
writeln(t)
End.
This code will correctly output the index of the maximum value in the array Dat.
The program is meant to find the maximum value in the array Dat and the index at which it occurs.
The correct syntax for the comparison statement is "if Dat[k] > m then" instead of "if Dat[k] >m then". The correct code should be:
Var k, m, t : integer;
Dat: array[1..10] of integer;
Begin
Dat[1] := 36; Dat[2] := 50;
Dat[3] := 23; Dat[4] :=41;
Dat[5] := 27; Dat[6] := 22;
Dat[7] := 59; Dat[8] := 12;
Dat[9] := 65; Dat[10] := 35;
m := 0;
for k := 1 to 10 do
if Dat[k] > m then
begin
m := Dat[k];
t := k
end;
writeln(t)
End.
This code will correctly output the index of the maximum value in the array Dat.