how can we design a magic square in c++?or suggest me the
basic idea of it.
Answer Posted / ganesh kundapur
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 ? | 8 Yes | 3 No |
Post New Answer View All Answers
What is an example of genetic polymorphism?
What is a superclass in oop?
What is basic concept of oop?
What is oops?what is its use in software engineering?
Explain the advantages of inheritance.
What is multilevel inheritance?
What is the highest level of cohesion?
Is abstract thinking intelligence?
Is data hiding and abstraction same?
Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.
What is for loop and its syntax?
how to get the oracle certification? send me the answer
What is class and example?
What are oops methods?
Objective The objective of this problem is to test the understanding of Object-Oriented Programming (OOP) concepts, in particular, on encapsulation. Problem Description Create a program for managing customer’s bank accounts. A bank customer can do the following operations: 1. Create a new bank account with an initial balance. 2. Deposit money into his/her account. 3. Withdraw money from his/her account. For this operation, you need to output “Transaction successful” if the intended amount of money can be withdrawn, otherwise output “Transaction unsuccessful” and no money will be withdrawn from his/her account. Input The input contains several operations and is terminated by “0”. The operations will be “Create name amount”, “Deposit name amount”, or “Withdraw name amount”, where name is the customer’s name and amount is an integer indicating the amount of money. There will be at most 100 bank accounts and they are all created on the first month when the bank is opening. You may assume that all account holders have unique names and the names consist of only a single word. Output The output contains the transaction result of withdrawal operations and the final balance of all customers after some withdrawal and deposit operations (same order as the input). Sample Input Create Billy 2500 Create Charlie 1000 Create John 100 Withdraw Charlie 500 Deposit John 899 Withdraw Charlie 1000 0