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                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  OOPS
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
how can we design a magic square in c++?or suggest me the 
basic idea of it.
 Question Submitted By :: Shivna Soni
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how can we design a magic square in c++?or suggest me the basic idea of it.
Answer
# 1
Detail about the magic square
http://en.wikipedia.org/wiki/Magic_square.

To design a matrix sqaure, consider a 3X3 matrix.

n = 3;

* Fill the matrix with 0 or X. Start from the middle of the
first row ( i = 0, j = n/2)
+--+--+--+
|X_|1_|X_|
|X_|X_|X_|
|X_|X_|X_|

*. From 1, Go up rt corner(no row, and last column)(-1, 2),
and come down. and fill the next number at (2, 2)

X 1 X
X X X
X X 2

*. From 2, go right up corner( No  column, 2nd row)(1, -1)
and if not any column, take a left and fill the next number
at (1, 0)

X 1 X
3 X X
X X 2

* From 3, go right up(0,1), It's already accupied, so come
down(2, 0) and fill the next number at (2,0)
X 1 X
3 X X
4 X 2.

* From node 4(2,0), up right up (1, 1), Its not accupied,
fill the next number at (1, 1)

X 1 X
3 5 X
4 X 2.

* From 5(1,1), Go right up(0,2) and its not accupied, fill
the next number at (0, 2)
X 1 6
3 5 X
4 X 2

* From x(0,2), go right up(No row, no column), so come down
from 6(1, 2), Its not accupied fill with the next number 7
at (1, 2)

X 1 6
3 5 7
4 X 2

* From 7(1, 2), Go up rt(1st row, no column), so take a left
and fill the unfilled node (0, 0)

8 1 6
3 5 7
4 X 2

* From 8(0,0), take up rt( No row, 1st column), come down
and fill the unfilled node at ( 2, 1)

           8 1 6  sum = 15
           3 5 7  sum = 15
           4 9 2  sum = 15

     sum   15 15 15

     Diagonal sum = 15

Fallow the same procedure for 5X5, 7X7 square.
 
Is This Answer Correct ?    2 Yes 0 No
Ganesh Kundapur
 

 
 
 
Other OOPS Interview Questions
 
  Question Asked @ Answers
 
//what is wrong with the programme?? #include<iostream.h> template <class first> class dd { first i; public: void set(); void print(); }; void dd< first>:: set() { cin>>i; } void dd< first>::print() { cout<<"\n"<<i; } void main() { dd <char>g; g.set(); g.print(); }  1
difference between overloading and overridding  2
what is meant by files? Infosys2
what is the difference between class and object?  4
different types of castings Siemens3
wht is major diff b/w c and c++?  3
sir i want to know which posting to apply since i am BE CSE.. also want to know what are the rounds there for my interview...Expecting for ur valuable answer....  1
What is R T T I ? Ness-Technologies3
what is the main difference between c and c++? Microsoft26
Name an advantage of array over linked list? IBM12
features of OOPS Ness-Technologies5
What is late bound function call and early bound function call? Differentiate.  2
What is friend function? Wipro3
write a c++ program to find maximum of two numbers using inline functions.  1
What is virtual constructors/destructors?  3
what is the use of mutable key word HCL2
Which is the parameter that is added to every non-static member function when it is called?  3
In which cases you use override and new base?  1
Difference between realloc() and free? HP3
what is difference b/w object based and object oriented programming language? Infosys2
 
For more OOPS 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