Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. (*
  2.    adapted to Oberon-07 by 0CodErr, KolibriOS team
  3.                                                    *)
  4. (* ********* Zonnon online collection ***********
  5.  * Magic Squares
  6.  *
  7.  * This example is a part of Prof. Nikalus Wirth's book
  8.  * www.zonnon.ethz.ch/usergroup
  9.  * (c) ETH Zurich
  10.  *)
  11.  
  12. MODULE MagicSquares;   (*NW 11.8.97*)
  13.  
  14. IMPORT In, Out, Console;
  15.  
  16.  
  17. PROCEDURE Generate;  (*magic square of order 3, 5, 7, ... *)
  18. VAR
  19.     i, j, x, nx, nsq, n: INTEGER;
  20.     M: ARRAY 13, 13 OF INTEGER;
  21.  
  22. BEGIN
  23.     Out.String("Enter magic square order(3, 5, 7, ..., 13): "); In.Int(n); nsq := n * n; x := 0;
  24.     i := n DIV 2; j := n - 1;
  25.     WHILE x < nsq DO
  26.         nx := n + x; j := (j - 1) MOD n; INC(x);
  27.         Out.Int(i, 1); Out.Char(9X);
  28.         Out.Int(j, 1); Out.Ln;
  29.         M[i, j] := x;
  30.         WHILE x < nx DO
  31.             i := (i + 1) MOD n; j := (j + 1) MOD n;
  32.             INC(x); M[i, j] := x
  33.         END
  34.     END;
  35.     FOR i := 0 TO n - 1 DO
  36.         FOR j := 0 TO n - 1 DO Out.Int(M[i, j], 6) END;
  37.         Out.Ln
  38.     END
  39. END Generate;
  40.  
  41. BEGIN
  42.     Console.open;
  43.  
  44.     Generate;
  45.     Out.String("Press Enter to continue"); In.Ln;
  46.  
  47.     Console.exit(TRUE)
  48. END MagicSquares.