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 |
how to concatenate the two strings
How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?
main( ) { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %d \n”,a,*a,**a,***a); printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1); }
int swap(int *a,int *b) { *a=*a+*b;*b=*a-*b;*a=*a-*b; } main() { int x=10,y=20; swap(&x,&y); printf("x= %d y = %d\n",x,y); }
main() { int i=-1; +i; printf("i = %d, +i = %d \n",i,+i); }
main() { printf("%x",-1<<4); }
how many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!
main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
which function is used to clear the buffer stream on gcc? for example: I wrote following code on gcc #include<stdio.h> int main(void) { char ch; int a,b; printf("\nenter two numbers:\t"); scanf("%d%d",&a,&b); printf("enter number is %d and %d",a,b); printf("\nentercharacter:\t"); scanf("%c",&ch); printf("enter character is %c",ch); return 0; } in above progarm ch could not be scan. why?plz tell me solution.
what is the code of the output of print the 10 fibonacci number series
#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }
How to palindrom string in c language?