program MagicSquare; const MaxSquare = 15; type SquareRange = 1..MaxSquare; MagEltType = Integer; {must be a type with addition} MagSqType = array[SquareRange,SquareRange] of MagEltType; var MagSq : MagSqType; SqSize, J : SquareRange; Sum : MagEltType; {the sum of the first row} Magic : Boolean; procedure ReadMagSq(FSqSize : SquareRange; var FMS : MagSqType); {pre: FSqSize the array size; post: FMS contains FSqSize by FSqSize array} begin end;{ReadMagSq} procedure WriteSq(FSqSize : SquareRange; var FMS : MagSqType; FM : Boolean); {pre: FSqSize the array size; FM true if a Magic Square post: the array written with a message} begin end;{ReadMagSq} procedure CheckRows( FSum : MagEltType; FSqSize : SquareRange; FMS : MagSqType; var FM : Boolean); {pre: FMagic true; Sum has value; MagSqType has values post: FMagic true only if all rows sum to Sum} begin end;{Checkrows} procedure CheckCols( Sum : MagEltType; FSqSize : SquareRange; FMS : MagSqType; var FMagic : Boolean); {pre: FMagic true; Sum has value; MagSqType has values post: FMagic true only if all cols sum to Sum} begin end;{CheckCols} procedure CheckDiags( Sum : MagEltType; FSqSize : SquareRange; FMS : MagSqType; var FMagic : Boolean); {pre: FMagic true; Sum has value; MagSqType has values post: FMagic true only if all diagonals sum to Sum} begin end;{Checkdiags} begin{main} Write('Input max square size ( <',MaxSquare:2,') >'); ReadLn(SqSize); ReadMagSq(SqSize,MagSq); Sum := 0; for J := 1 to SqSize do Sum := Sum + MagSq[1,J]; Magic := True; CheckRows(Sum,SqSize,MagSq,Magic); if Magic then CheckCols(Sum,SqSize,MagSq,Magic); if Magic then CheckDiags(Sum,SqSize,MagSq,Magic); WriteSq(SqSize,MagSq,Magic) end.{main}