下面的代码应该创建一个3x4矩阵,并打印每行所有数字的总和。但是,在编译它时,我不断收到以下错误:
jdoodle.pas(26,25) Error: Illegal qualifier
jdoodle.pas(33,32) Error: Illegal qualifier
jdoodle.pas(41,32) Error: Illegal qualifier
jdoodle.pas(48,24) Error: Illegal qualifier
jdoodle.pas(56,4) Fatal: There were 4 errors compiling module, stopping
Fatal: Compilation aborted.
有问题的行是:
line 26: readln (A[i, j]);
line 33: B[i] := B[i] + A[i, j]
line 41: C[J] := C [J] + A[i,j]
line 48: write (A[i, j]:5);
有人可以为我澄清一下吗?主要问题是,我真的不知道错误代码的含义。我注意到了A [i,j]'在错误中提到的所有行中,但我无法找出它的错误。非常感谢任何帮助!
这是我的完整代码:
Program Matrix (input, output);
const
ZEILENMAX = 3;
SPALTENMAX = 4;
type
tZeile = 1..ZEILENMAX;
tSpalte = 1..SPALTENMAX;
tMatrix = array[tZeile] of integer;
tZeilensumme = array [tZeile] of integer;
tSpaltensumme = array [tSpalte] of integer;
var
A : tMatrix;
B : tZeilensumme;
C : tSpaltensumme;
i : tZeile;
j : tSpalte;
begin
for i := 1 to ZEILENMAX do
for j := 1 to SPALTENMAX do
readln (A[i, j]);
for i := 1 to ZEILENMAX do
begin
B[i] := 0;
for j := 1 to SPALTENMAX do
B[i] := B[i] + A[i, j]
end;
for j := 1 to SPALTENMAX do
begin
C[j] := 0;
for i := 1 to Zeilenmax do
C[J] := C [J] + A[i,j]
end;
writeln;
for i := 1 to ZEILENMAX do
begin
for j := 1 to SPALTENMAX do
write (A[i, j]:5);
writeln (B[i]:10)
end;
writeln;
for j:= 1 to SPALTENMAX do
write (C[j]:5);
writeln
end.
答案 0 :(得分:0)
让我们转录下面的代码:
const
ZEILENMAX = 3;
type
tZeile = 1..ZEILENMAX;
tMatrix = array[tZeile] of integer;
var
A : tMatrix;
等于:
type
tZeile = 1..3;
tMatrix = array[tZeile] of integer;
var
A : tMatrix;
这类似于:
type
tMatrix = array[1..3] of integer;
var
A : tMatrix;
一个索引可以访问数组A
的成员:
A[1] := 0;
但不是A[1,1] := 1
或类似。