answersLogoWhite

0

#include<stdio.h>

#include<string.h>

void main()

{

int kute=0;

int ms[100][100],n,i,j,num;

while(scanf("%d",&n)==1)

{

if(!n%2)

{

printf("Enter a odd number 1-99\n");

continue;

}

memset(ms,0,sizeof(ms));//set all element to 0 as well false

num=1;i=n/2;j=n-1;//1st step

while(1)

{

if(num>n*n)break;

if(i==-1&&j==n){j=n-2;i=0;}//3rd condition

else {

if(j==n)j=0;//1st condition helper if next number is goes to out of box right side

if(i<0)i=n-1;//1st condition helper if next number is goes to out of box upper side

}

if(ms[i][j]){j--;j--;i++;continue;}//2nd condition

else

ms[i][j]=num++;//set number

j++,i--;//1st condition

}

//print magic square

printf("The Magic Square for %d:\nSum of each row or column %d:\n\n",n,(n*n*n+n)/2);

for(i=0;i<n;i++)

{

for(j=0,num=0;j<n;j++)

{

printf("%2d ",ms[i][j]);

num+=ms[i][j];

}

printf(" %d\n\n",num);

}

getch();

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What does evenly and doubly even mean?

A number is even if it is divisible by 2. It is doubly even if it is divisible by 4.


Does the number 5 always have to be in the middle of a magic square?

Think! What if the magic square had an even number of cells. There's your answer.


Construct a magic square of 3 x 3 which has magic constant of 30?

Magic squares have been a source of intrigue since the time of Pythagoras, and even before. You will find the following link useful.


How can you learn magic?

depends on what you mean magic tricks or actual magic magic tricks can easily be learned from magic trick set. real magic on the other hand is harder to aquire if even real but would probably be very hard to learn if it can even be taught.


How do you calculate a magic square?

To calculate a magic square, start by determining its order (n), which is the number of rows or columns. For an n x n magic square, the magic constant (the sum of each row, column, and diagonal) is given by the formula ( M = \frac{n(n^2 + 1)}{2} ). You can then fill the square using specific methods, such as the Siamese method for odd-order squares, where you place numbers starting from the center of the top row and move diagonally up and right, wrapping around when necessary. Adjust placements as needed for even-order squares using different strategies, such as the Strachey or complementary methods.


What number is not an even number and or a square number?

25 25 is not even and is a square. 3 is not even or a square.


Is the square of an even number odd or even?

The square of an even number is always even.


What number is an even square number?

Any even number you square will give you a even square number =)


What is Selena Gomez's song it's magic about?

Nobody knows. Not even Selena. Not even Disney. It's a secret. Muggles shouldn't know about magic.


What state did Robert E Lee surrendered his army in?

Virginia - doubly painful for him, as he had joined the Confederates for the purpose of defending Virginia, his home state, even though he disapproved of secession.


What is an even number and a square number?

An even number is any integer that can be divided by two evenly. A square number is any integer multiplied by itself. 2 is even 3 is odd 4 is even and a square of 2 9 is odd and a square of 3 The square of any even number will itself be an even number, and the square of any odd number will itself be an odd number.


Is there an action replay code for sonic adventure DX GCN that allows you to play as metal sonic in station square?

yes their is a cheat code that enables play of metal sonic in levels even a gold metal sonic