I need help on creating a 5x5 magic sqaure on f77.
If anyone can help!
A magic square is an N x N matrix in which all
the integers 1,2, . . . N^2
appear exactly once, and all the rows, columns,
and diagonals yield the
same sum. An example of a 5X5 magic square is
given below (the sum is 65).
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
This is the logic I came up with from a Linear
Algebra Book:
I Place an integer 1 in the middle of the top
row. Then, after placing integer K, move up one
row and to the right one column to place the next
integer (integer K+1), UNLESS one of the
following occurs:
If a move takes you above the top row in the jth
column, move to the bottom of the jth column and
place the integer there.
If a move takes you outside to the right of the
square in the ith row,place the integer in the ith
row at the left side.
If a move takes you to an already filled square,
or if you move out of the square at the upper
right-hand corner, place integer K+1 immediately
below integer K.
I need to write a program that will construct and
print a magic square for
any odd integer N. In addition to printing the
magic square, it should
also print the row/column/diagonal sum , like 65
in the example above.
If anyone knows/can help with the f77 code, I'd
appreciate it.
Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.