Virtual Helper


Any small thing looked at a greater depth have excellent structure or pattern behind them


My parallelogram law of forces

Philosophy of Mathematics

Is Mathematics really Hard?(specially for those who hate it).I have expressed my views regarding mathematics.How Mathematics is associated with all walks of human life.

learn more

Web technology

Everything in the world is connected.This is another nice article related to div tag.

learn more

Another webtechnology post

Funny illustration of webtechnology related concept.How web technology various branches associated with the human life

learn more

Free Educational Video

Treasure Resources

All open resources Educational resources under one shell for all subjects .Don't forgot to bookmark this.

learn more

C program for odd order magic squares generalized



#include<stdio.h>
void main()
{
int n;
// int i=0,j,k=1,a[15][15];
//clrscr();
printf("n Enter any odd number>1 t");
scanf("%d",&n);
if(n%2==0)
{
printf("This program works only for odd numbersn");

}
else
{
int i=0,j,k=1,a[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=0;
}

}
i=0;
j=n/2;

a[i][j]=k;

while(k<(n*n))
{
i=i-1;
j=j+1;
if((i<0)&&(j>=n))
{
j=j-1;
i=i+2;

}
else if(i<0)
{
i=n-1;
}
else if(j>=n)
{
j=0;
}
// else
// {
if(a[i][j]!=0)
{
j=j-1;
i=i+2;

}
k=k+1;
a[i][j]=k;

// }


}
printf("n the magic squares for given order isn");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%dt",a[i][j]);
}
printf("n");
}



}


getch();
}


Responses

0 Respones to "C program for odd order magic squares generalized"

Post a Comment

 
Return to top of page Copyright © 2010 | Platinum Theme Converted into Blogger Template by HackTutors