Advertisement

Magic Squares formula?

Started by January 20, 2001 01:01 PM
0 comments, last by Ramza 24 years ago
Hi, I'm taking computer science 1 in my high school and I have a bit of a problem. For a program we have to design (in True Basic) we have to display magic squares for any odd number entered by the user. I was wondering if anyone knows an algorithm or formula to do this. Thanks, Chris *Edit: Use a little sense in making up your subject line rather than just yelling help. -fel* Edited by - felisandria on January 21, 2001 2:18:01 PM
Now, let me help you. I will not tell you how to calculate the magic squares. I have one primary reason for this:
1. Giving you the answer, will not help you better your problem solving skills.

Ok. Now that this is out of the way. I will give you a hint, as to how I would attack the problem.
When you have to solve these ''for any number problems'' try to look for patterns for the different numbers.
Take a piece of graph paper, and make some magic squares for some low odd numbers like 3,5,7,9, etc.
Ok, now try to look for similar patterns; do two magic squares of different sizes have anything in common, in the way they are calculated or in the way the numbers are laid out? How about two different squares of the same size?
If you find any patterns, try to generalize it for a square of any odd size. If you can do this, you just made the algorithm yourself.

I am not sure this method works here, but it is how I would initially attack the problem. Good Luck.

Gorm

This topic is closed to new replies.

Advertisement