odd magic square

odd magic square

Page 1 of 1

2 Replies - 13467 Views - Last Post: 28 April 2008 - 05:27 PM Rate Topic: -----

#1 thiruppathi25  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-March 08

odd magic square

Posted 20 March 2008 - 06:51 AM

hi
i want the program of odd magic square.pls send this program its very urgent for me pls send

thank you
Is This A Good Question/Topic? 0
  • +

Replies To: odd magic square

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: odd magic square

Posted 20 March 2008 - 06:57 AM

Please very urgent read the rules to this forum!!!

All odd magic squares can be solved using a simple algorithm (there are many, but you only need to code one). For example, place 1 in the top middle square and move diagonally up and to the right (wrapping) 2, 3, etc... when you come to a square that is already filled, then move down 1 square and continue. When all squares are complete you have filled out the magic square.

Other than that:

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 Nidal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-April 08

Re: odd magic square

Posted 28 April 2008 - 05:27 PM

View Postthiruppathi25, on 20 Mar, 2008 - 06:51 AM, said:

hi
i want the program of odd magic square.pls send this program its very urgent for me pls send

thank you


You're Lazy:

But Here is a Perfect Working Odd Magic Square C Program:

NIDAL

Enjoy:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{

printf("\n\n\n\n");
printf("Welcome To The Odd Magic Square Generator\n\n");
printf("It Will Prompt For Inputs Until The User Enters A Negative One (i.e. '-1')\n\n");
printf("Enjoy!\n\n\n");

int N;
int A;
int B;
int C=1;
int INVALID = -1;
int X;
int Y;

while (1)
{
N=0;
A=0;
B=0;
C=1;
X=0;
Y=0;
while ((N%2==0) || (N<3))
{
printf("Please Enter a Odd Number That is Greater Than 3: ");
scanf("%d", &N);
if (N==-1)
{
exit (0);
}
printf("\n");
}

int S[N][N];


for (A=0; A<N; A++)
{
for (B=0; B<N; B++)
{
S[A][B]=INVALID;
}
}


X=0;
Y=(N/2);

for (A=0; A<(N*N); A++)
{
S[X][Y]=C++;

if (--X<0)
{
X=N-1;
}
if (--Y<0)
{
Y=N-1;
}

if (S[X][Y] != INVALID)
{
for (B=0; B<2; B++)
{
if (++X > (N-1))
{
X=0;
}
}
if (++Y > (N-1))
{
Y=0;
}

}
}



int T;
T=(((N*N*N)+N)/2);
printf("The Follwing Magic Square Adds Up To: [#%d]\n\n", T);

for(X=0; X<=(N-1); X++)
{
for(Y=0; Y<=(N-1); Y++)
{
printf("%d\t", S[X][Y]);
}
printf("\n");
}
printf("\n");
}
}
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1