Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

program to find the magic square

Answer Posted / balaji ganesh

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int S[15][15],z=1,m,n,i,j,b=1,C,X,Y,T,p=0;
clrscr();
scanf("%d",&n,printf("enter size of magic square you
want:"));
while(z)
{
for (i=0; i<n; i++)
for (j=0; j<n; j++)

S[i][j]=-1;
X=0;
Y=(n/2);

C=b;
for (i=0; i<(n*n); i++)
{
S[X][Y]=C++;
if (--X<0) X=n-1;
if (--Y<0) Y=n-1;
if (S[X][Y] !=-1)
{
for (j=0; j<2; j++)
if (++X > (n-1))
X=0;

if (++Y > (n-1)) Y=0;
}
}
T=(((n*n*n)+n)/2)+p;
printf("\nThe Follwing Magic Square Adds Up
To: %d\n\n", T);
for(i=0; i<=(n-1); i++)
{
for(j=0; j<=(n-1); j++)
printf("%d\t", S[i][j]);
printf("\n\n");
}
printf("\n");
scanf("%d",&z,printf("if u want another
magic square for same size enter any num (to exit 0):"));
b++;p+=n;
}
getch();
}


Is This Answer Correct ?    5 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is pointers in c?

1126


What is the method to save data in stack data structure type?

1097


What are the types of operators in c?

1077


the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above

1272


Can you assign a different address to an array tag?

1181


please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com

1785


how do you execute a c program in unix.

1126


What is the scope of an external variable in c?

1063


write a program fibonacci series and palindrome program in c

1061


please explain every phase in the "SDLC" in the dotnet.

2634


disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit

2080


Can static variables be declared in a header file?

1073


Write a program that accept anumber in words

1772


Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?

1116


I came across some code that puts a (void) cast before each call to printf. Why?

1232