2017-10-11 72 views
0

下面的代碼應該創建一個3x4矩陣並打印每行所有數字的總和。然而,在編譯它,我不斷收到以下錯誤:有問題Pascal錯誤:非法限定符

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. 
+2

在您的聲明中,'A'看起來不像多維數組。 – pvg

+0

@pvg你能澄清嗎?矩陣不算作多維數組嗎? (對不起,這裏是初學者) – Lucky

+0

'矩陣'只是你給出類型的名字。你已經將它聲明爲一維數組,就像其他數組一樣。你爲什麼期望A是多維的,而B和C是一維的,具有完全相同的聲明?如果你對聲明語法不清楚,可以Google'在Pascal中創建多維數組'。 – pvg

回答

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; 

,這是類似到:

陣列 A的個

成員可以通過訪問的單個指數: A[1] := 0;但不A[1,1] := 1或類似物。

+1

@lurker和平片:-)更正。請,請隨時糾正我的任何帖子)) –