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 |
main() { void swap(); int x=10,y=8; swap(&x,&y); printf("x=%d y=%d",x,y); } void swap(int *a, int *b) { *a ^= *b, *b ^= *a, *a ^= *b; }
respected sir, i did my MCA in 2013 when i am going to attend to an interview i was asked about my project how will i explain my project could please help me in this and my project title is "Social Networking Site For Social Responsibility"
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }
/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }
Write a program using one dimensional array to assign values and then display it on the screen. Use the formula a[i]=i*10 to assign value to an element.
1 Answers Samar State University,
Is the following code legal? struct a { int x; struct a *b; }
What is full form of PEPSI
main() { printf("%d, %d", sizeof('c'), sizeof(100)); } a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4
18 Answers HCL, IBM, Infosys, LG Soft, Satyam,
main( ) { void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp); vp = &j; printf(“%d”,*(int *)vp); vp = cp; printf(“%s”,(char *)vp + 3); }
create a login program that ask username and password. if you input username or password 3 times wrong, the program will terminate else the program will prompt a message "congratulations"
plz tell me the solution.......... in c language program guess any one number from 1 to 50 and tell that number within 8 asking question in yes or no...............
Write a function to find the depth of a binary tree.
13 Answers Adobe, Amazon, EFI, Imagination Technologies,