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 |
Write a C program to perform some of the operation which can be performed using Single linked list
how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please mail me the code if any one know to rajeshmb4u@gmail.com
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
Why does not use getgh(); and <conio.h> in c language.
What is calloc() function?
x=y=z=1 z=++x||++y&&++z Printf("%%%d";xyz) what is the values of x,y and z?????
write a c program to find reminder and quotient if one number is divided by other.to code this program don't use more than 2 variables
How can type-insensitive macros be created?
enum day = { jan = 1 ,feb=4, april, may} what is the value of may? a)4 b)5 c)6 d)11 e)none of the above
What is c programing language?
When we use void main and int main?
What is structure padding and packing in c?