title: Magic Square FreePascal
body: <p>Program must output whether the square is magic square or not.</p>
  
  <p>I must read square from file.</p>
  
  <p>Magic square - all rows, all columns and both diagonals sum must be equal.</p>
  
  <p>Program shows right answer, but these 16 numbers must be read from text file.</p>
  
  <p>Text file is looking like:</p>
  
  <pre><code>1 1 1 1
  2 2 2 2 
  3 3 3 3
  4 4 4 4
  </code></pre>
  
  <p>Program itself: </p>
  
  <pre><code>var
    m:array[1..4,1..4] of integer;
    i:byte;
    j:byte;
    r1,r2,r3,r4,c1,c2,c3,c4,d1,d2:integer;
  
  begin
  
  for i:=1 to 4 do
    for j:=1 to 4 do
  
    begin
      write('Enter value for column=',i,' row=',j,'  :');
      readln(m[i,j]);
    end;
  
  r1:=m[1,1]+m[1,2]+m[1,3]+m[1,4];
  r2:=m[2,1]+m[2,2]+m[2,3]+m[2,4];
  r3:=m[3,1]+m[3,2]+m[3,3]+m[3,4];
  r4:=m[4,1]+m[4,2]+m[4,3]+m[4,4];
  c1:=m[1,1]+m[2,1]+m[3,1]+m[4,1];
  c2:=m[1,2]+m[2,2]+m[3,2]+m[4,2];
  c3:=m[1,3]+m[2,3]+m[3,3]+m[4,3];
  c4:=m[1,4]+m[2,4]+m[3,4]+m[4,4];
  d1:=m[1,1]+m[2,2]+m[3,3]+m[4,4];
  d2:=m[1,4]+m[2,3]+m[3,2]+m[4,1];
  
  if (r1=r2) and (r2=r3) and (r3=r4) and (r4=c1) and (c1=c2) and (c2=c3) and (c3=c4) and (c4=d1) and (d1=d2) then
    begin
    write('Magic Square');
    end
  
  else
    begin
    write('Not Magic Square');
    end;
  
  readln;
  
  end.
  </code></pre>