C program to print magic square of order n where n > 3 and n
is odd
Answers were Sorted based on User's Feedback
Answer / aparna v
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20][20],r,c,br,bc,k,n;
clrscr();
printf("Enter the Order of Magic Square(Odd): ");
scanf("%d",&n);
for(r=0;r<n;r++)
for(c=0;c<n;c++)
a[r][c]=0;
r=0;
c=n/2;
for(k=1;k<=n*n;k++)
{
a[r][c]=k;
br=r++;bc=c++;
r=(r+1)%n;
c=(c+1)%n;
if(a[r][c]!=0)
{
c=bc;
r=br-1;
if(r<0)r=n-1;
}
}
printf("The Magic Square...\n");
for(r=0;r<n;r++)
{
for(c=0;c<n;c++)
printf("%4d",a[r][c]);
printf("\n");
}
}
Read more:
http://www.funonthenet.in/forums/index.php?topic=25587.0#ixzz1YUKtxDVT
Is This Answer Correct ? | 21 Yes | 5 No |
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }
#include <stdio.h> #define a 10 main() { #define a 50 printf("%d",a); }
#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }
Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];
Develop a routine to reflect an object about an arbitrarily selected plane
find A^B using Recursive function
main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }
source code for delete data in array for c
how can u draw a rectangle in C
53 Answers Accenture, CO, Codeblocks, Cognizant, HCL, Oracle, Punjab National Bank, SAP Labs, TCS, University, Wipro,
write a simple calculator c program to perform addition, subtraction, mul and div.
0 Answers United Healthcare, Virtusa,
int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }
void main() { int i=i++,j=j++,k=k++; printf(“%d%d%d”,i,j,k); }