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 |
#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }
Is it possible to type a name in command line without ant quotes?
String reverse with time complexity of n/2 with out using temporary variable.
#include<stdio.h> #include<conio.h> void main() { int a=(1,2,3,(1,2,3,4); switch(a) { printf("ans:"); case 1: printf("1");break; case 2: printf("2");break; case 3: printf("1");break; case 4: printf("4");break; printf("end"); } getch(); }
program to find the roots of a quadratic equation
14 Answers College School Exams Tests, Engineering, HP, IIIT, Infosys, Rajiv Gandhi University of Knowledge Technologies RGUKT, SSC,
main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }
main() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }
Is it possible to print a name without using commas, double quotes,semi-colons?
#define prod(a,b) a*b main() { int x=3,y=4; printf("%d",prod(x+2,y-1)); }
What is the main difference between STRUCTURE and UNION?
source code for delete data in array for c
Sorting entire link list using selection sort and insertion sort and calculating their time complexity
1 Answers Infosys, Microsoft, NetApp,