program to find the magic square
Answer / 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 |
4) Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
What is the difference between declaring a variable by constant keyword and #define ing that variable?
How can I sort more data than will fit in memory?
Write a code to generate divisors of an integer?
what is the difference b/w compiler and debugger?
Explain continue keyword in c
struct tag{ auto int x; static int y; };main() { struct tag s; s.x=4; s.y=5; printf(ā%dā,s.x); }
What are reserved words?
What is || operator and how does it function in a program?
What is Generic pointer? What is the purpose of Generic pointer? Where it is used?
Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.
how to find out the reverse number of a digit if it is input through the keyboard?