program to find magic aquare using array
Answers were Sorted based on User's Feedback
Answer / aditya raj
// magic square for odd numbers....
#include<stdio.h>
main()
{
int n;
scanf("%d",&n);
int a[n][n],i,j;
int row[n],col[n],dia[2]={0};
for(i=0;i<n;i++)
{
row[i]=0;
col[i]=0;
}
int num=1;
int nn=n*3/2;
for(i=0; i < n; i++)
for(j=0; j < n; j++)
a[(j-i+nn)%n][(i*2-j+n)%n]=num++;
for(i=0; i < n; i++)
{ for(j=0; j < n; j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
}
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / anurag
This is the link to read something about the magic aquare.
try it.
htp://mathworld.wolfram.com/MagicSquare.html
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / aditya raj
// magic square for odd numbers....
#include<stdio.h>
main()
{
int n;
scanf("%d",&n);
int a[n][n],i,j;
int row[n],col[n],dia[2]={0};
for(i=0;i<n;i++)
{
row[i]=0;
col[i]=0;
}
int num=1;
int nn=n*3/2;
for(i=0; i < n; i++)
for(j=0; j < n; j++)
a[(j-i+nn)%n][(i*2-j+n)%n]=num++;
for(i=0; i < n; i++)
{ for(j=0; j < n; j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
}
Is This Answer Correct ? | 0 Yes | 1 No |
main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }
Print an integer using only putchar. Try doing it without using extra storage.
main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024
main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }
find A^B using Recursive function
How to return multiple values from a function?
There are 21 people in a room. They have to form groups of 3 people each. How many combinations are possible? Write a C program to print the same.
writte a c-programm to display smill paces
union u { union u { int i; int j; }a[10]; int b[10]; }u; main() { printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a)); // printf("%d", sizeof(u.a[4].i)); } a. 4, 4, 4 b. 40, 4, 4 c. 1, 100, 1 d. 40 400 4
How can you relate the function with the structure? Explain with an appropriate example.
Write a program to print a square of size 5 by using the character S.