Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details

2 Answers   TCS,


source code for delete data in array for c

1 Answers   TCS,


main() { main(); }

1 Answers  


main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a); } abc(char a[]){ a++; printf("%c",*a); a++; printf("%c",*a); }

2 Answers  


void main() { int c; c=printf("Hello world"); printf("\n%d",c); }

2 Answers  


#include<stdio.h> void fun(int); int main() { int a; a=3; fun(a); printf("\n"); return 0; } void fun(int i) { if(n>0) { fun(--n); printf("%d",n); fun(--n); } } the answer is 0 1 2 0..someone explain how the code is executed..?

1 Answers   Wipro,


Is the following code legal? struct a { int x; struct a b; }

1 Answers  


Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba. You can assume that all the characters will be unique.

5 Answers   IITR, Microsoft, Nike,


main() { float f=5,g=10; enum{i=10,j=20,k=50}; printf("%d\n",++k); printf("%f\n",f<<2); printf("%lf\n",f%g); printf("%lf\n",fmod(f,g)); }

1 Answers  


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

1 Answers  


main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

1 Answers  


In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. main(){ int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }

1 Answers  


Categories