ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
program to find magic aquare using array
 Question Submitted By :: Nithya
I also faced this Question!!     Rank Answer Posted By  
 
  Re: program to find magic aquare using array
Answer
# 1
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
Anurag
 
  Re: program to find magic aquare using array
Answer
# 2
// 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 ?    3 Yes 0 No
Aditya Raj
 
 
 
  Re: program to find magic aquare using array
Answer
# 3
// 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 0 No
Aditya Raj
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.  2
int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }  1
main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }  1
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }  1
What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ }  1
Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?  1
Is the following code legal? struct a { int x; struct a b; }  1
What is the hidden bug with the following statement? assert(val++ != 0);  1
main() { int x=5; clrscr(); for(;x==0;x--) { printf("x=%d\n”", x--); } } a. 4, 3, 2, 1, 0 b. 1, 2, 3, 4, 5 c. 0, 1, 2, 3, 4 d. none of the above HCL1
struct point { int x; int y; }; struct point origin,*pp; main() { pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); printf("origin is (%d%d)\n",pp->x,pp->y); }  1
main() { printf("%d, %d", sizeof('c'), sizeof(100)); } a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4 HCL3
main() { if ((1||0) && (0||1)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above HCL1
char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)  1
Derive expression for converting RGB color parameters to HSV values  1
#include"math.h" void main() { printf("Hi everybody"); } if <stdio.h> will be included then this program will must compile, but as we know that when we include a header file in "" then any system defined function find its defination from all the directrives. So is this code of segment will compile? If no then why?  2
main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }  1
#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }  1
Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution) Microsoft5
how to check whether a linked list is circular.  3
main() { int i =10, j = 20; clrscr(); printf("%d, %d, ", j-- , --i); printf("%d, %d ", j++ , ++i); } a. 20, 10, 20, 10 b. 20, 9, 20, 10 c. 20, 9, 19, 10 d. 19, 9, 20, 10 HCL1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com