| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- (*
- adapted to Oberon-07 by 0CodErr, KolibriOS team
- *)
- (* ********* Zonnon online collection ***********
- * Magic Squares
- *
- * This example is a part of Prof. Nikalus Wirth's book
- * www.zonnon.ethz.ch/usergroup
- * (c) ETH Zurich
- *)
- MODULE MagicSquares; (*NW 11.8.97*)
- IMPORT In, Out, Console;
- PROCEDURE Generate; (*magic square of order 3, 5, 7, ... *)
- VAR
- i, j, x, nx, nsq, n: INTEGER;
- M: ARRAY 13, 13 OF INTEGER;
- BEGIN
- Out.String("Enter magic square order(3, 5, 7, ..., 13): "); In.Int(n); nsq := n * n; x := 0;
- i := n DIV 2; j := n - 1;
- WHILE x < nsq DO
- nx := n + x; j := (j - 1) MOD n; INC(x);
- Out.Int(i, 1); Out.Char(9X);
- Out.Int(j, 1); Out.Ln;
- M[i, j] := x;
- WHILE x < nx DO
- i := (i + 1) MOD n; j := (j + 1) MOD n;
- INC(x); M[i, j] := x
- END
- END;
- FOR i := 0 TO n - 1 DO
- FOR j := 0 TO n - 1 DO Out.Int(M[i, j], 6) END;
- Out.Ln
- END
- END Generate;
- BEGIN
- Console.open;
- Generate;
- Out.String("Press Enter to continue"); In.Ln;
- Console.exit(TRUE)
- END MagicSquares.
|