program to find magic aquare using array

Answers were Sorted based on User's Feedback



program to find magic aquare using array..

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

program to find magic aquare using array..

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

program to find magic aquare using array..

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

program to find magic aquare using array..

Answer / radhika

Nine

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Code Interview Questions

main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }

1 Answers  


enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }

2 Answers  


Print an integer using only putchar. Try doing it without using extra storage.

2 Answers  


main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024

2 Answers   HCL,


main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }

1 Answers  


find A^B using Recursive function

2 Answers  


How to return multiple values from a function?

7 Answers  


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.

1 Answers   TCS,


writte a c-programm to display smill paces

2 Answers  


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

3 Answers   HCL,


How can you relate the function with the structure? Explain with an appropriate example.

0 Answers  


Write a program to print a square of size 5 by using the character S.

6 Answers   Microsoft,


Categories