Search Tutorials

Saturday, 20 April 2013

Magic Square program in c

#include<stdio.h>
#include<conio.h>

int main()
{

 int i,j,n,num,a[100][100];
// clrscr();
 printf ("enter any odd no.:");
 scanf("%d",&n );
 i=n-1;
 j=(n-1)/2;
  if(n%2==0)
  {  printf(" enter only odd no.");}

  else
  {

   for(num=1;num<=n*n;num++)
 {
  a[i][j]=num;
  i++;
  j--;
  if(num%n==0)
    {i-=2;
     j++;
    }

  if(i==n)
    i=0;
  if(j==-1)
    j=n-1;


 }

 for(i=0;i<n;i++)
  { for(j=0;j<n;j++)
    printf("%4d ",a[i][j]);
    printf("\n");
  }
   }
 getch();
}

2 comments:

  1. Nice post, It is major to comprehend the likelihood of the distraction and try to play as shown by the circumstance. Everything considered, your homepage is stacked with various and spellbinding distractions. This is to an extraordinary degree so solid data for me and I learn stores of the things.

    ReplyDelete
  2. Working and studying. Time is constantly not enough. But you need to write an essay. I found a great solution http://essaylab.co.uk/ You can order the service at any time of the day or night. Always on time. And the prices are excellent.

    ReplyDelete

Back to Top