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 |
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 program in c language to get the value of arroy keys pressed and display the message which arrow key is pressed?
main() { char *p="GOOD"; char a[ ]="GOOD"; printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p)); printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a)); }
Find your day from your DOB?
15 Answers Accenture, Microsoft,
main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
Write a program to implement the motion of a bouncing ball using a downward gravitational force and a ground-plane friction force. Initially the ball is to be projected in to space with a given velocity vector
void main() { int i; char a[]="\0"; if(printf("%s\n",a)) printf("Ok here \n"); else printf("Forget it\n"); }
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.
Write a routine to implement the polymarker function
Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };
Write a complete program that consists of a function that can receive two numbers from a user (M and N) as a parameter. Then print all the numbers between the two numbers including the number itself. If the value of M is smaller than N, print the numbers in ascending flow. If the value of M is bigger than N, print the numbers in descending flow. may i know how the coding look like?
how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.
0 Answers Mbarara University of Science and Technology,