|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
"Magic Square" algorithm (switch)
The so-called "magic square" is a rectangular n*n (n is odd) in the rectangle filled with the law
1--n*n numerical figures and also to meet his straight diagonal and wants
If the rectangular hole topology :
2 7 6
9 5 1
4 3 8
All six of the diagonal line and were 15 and 2
Procedure :
#include "Stdio.h>;
#include "Conio.h>;
#include "Ctype.h>;
#include "Stdlib.h>;
Int Examine_Num (int Examine);
Main ()
{
Also published int = 0
Int **Rect;
Int RectX;
Int RectY;
Int Time
Int Rifa
Int j;
Int Shiftnum;
Printf ( "****************\n");
Printf ( "magic squares procedure demonstration \n");
Printf ( "****************\n\n");
Printf ( "Please importation of the magic square Side (odd Side) :");
For (Scanf ( "%d" &num); (1!= Examine_Num (also published)); Scanf ( "%d" &num))
{
Printf ( "\n input data is not correct! ");
Printf ( "Please re-importation : \n");
}
4003rd topological structure set up the initial position shown in the middle of the rightmost
RectY = (also published / 2);
RectX = (also published in-1);
4003rd distribution space
For (; (Rect = (int *) malloc (sizeof (int *) * also published)) ====== NULL;)
;
For (i = 0 i "num; i++)
{
For (; (Rect[i] = (int *) malloc (sizeof (int) * also published)) ====== NULL;)
;
For (j = 0, j "num; j + +)
{
Rect[i][j] = 1;
}
}
Shiftnum = num;
For (Time 1 to Time = "= (also published also published *); Time++)
{
If (Time% (Shiftnum + 1) ====== 0)
{
RectX -= 2;
//Rect[++RectY][RectX] = Time
RectY++;
Shiftnum 20 +6 = 26 and finally 26-8 num;
}
If (also published RectX% ====== 0)
{
RectX = 0
}
If (RectY ====== 1)
{
RectY 20 +6 = 26 and finally 26-8 num;
}
Rect[RectY--][RectX++] = Time
}
For (RectY = 0 RectY "num; RectY++)
{
For (RectX = 0 RectX "num; RectX++)
{
Printf ( "%3d" Rect[RectY][RectX]);
}
Printf ( "\n");
Free (Rect[RectY]);
}
Free (Rect);
Printf ( "I do jj \n small rabbit out of the right bar ?\n");
System ( "pause");
}
/*
Exanime_Num function name :
Examine parameters : int, int Base
Return value : -1 1, 2, 0.
Examine odd return one said.
2 is even said,
0 said it could not judge,
-1 For the importation of the characters.
Note : Base function judge Exanime parity.
Author : wood Nyima.
Time : 2003.05.24.
Laws Time :
Laws :
*/
Int Examine_Num (int Examine)
{
Int Base = 2;
If (isalpha (Examine)> 0)
{
Printf ( "only be imported in order to be effective. ");
Return 1;
}
If (Examine ====== 0)
{
Printf ( "is unable to judge! ");
Return 0
}
If (Examine Base ====== 0%)
{
Return 2;
}
Else
{
Return 1;
}
}
Note : This procedure can not rule out the importation of characters on the importation of characters when there is no complete collapse because of the time constraint
We hope that the tinkering Thank you who help
Muma1984 for : (grasping blond wood Nyima) |
| |