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
Differentiate fundamental data types and derived data types in C.
What are the main characteristics of c language describe the structure of ac program?
Do you know null pointer?
Why c language is called c?
What is file in c language?
What does the file stdio.h contain?
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above
Explain the use of function toupper() with and example code?
What is static identifier?
can any one tel me wt is the question pattern for NIC exam
State two uses of pointers in C?
What are the 32 keywords in c?
write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a
How old is c programming language?
What does return 1 means in c?