Reference no: EM13693811
Program Specification: An n x n matrix that is filled with the whole numbers 1, 2, 3, .. n2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value.
Here is a magic square where n = 3:
8 1 6
3 5 7
4 9 2
Program: Write a program that reads n2 numbers from standard input and tests whether they form a magic square when put into matrix form.
The value of n is NOT an input to the program; n must be determined from the number of inputs.
For example, the input that creates the example matrix above is 8 1 6 3 5 7 4 9 2.
The output is a single word, "true" if the input produces a magic square, "false" otherwise. Your program may assume that each input token is a whole number.
The program must verify:
1. The proper number of input values was provided.
2. Each of the numbers between 1 and n2 occurs exactly once in the input.
3. When the numbers are arranged in a matrix,
- the sum of the rows,
- columns,
- and diagonals must be the same value.
You need to make well-formed and clean code. You should not copy and paste the code from other source.
Consider pollution control in the electric industry
: Consider pollution control in the electric industry. The prices of marketable permits are set by:
|
Minimum annual production rate to make this investment
: A manufacturing company is considering a capacity expansion investment at the cost of $245,219 with no salvage value. The expansion would enable the company to produce up to 35,887 parts per year and the useful life of the additional capacity is seve..
|
Economists occasionally speak of helicopter money
: Economists occasionally speak of “helicopter money” as a short-hand approach to explaining increases in the money supply. Suppose the Governor of the Fed flies over the country in a helicopter dropping 10,000,000 in newly printed $100 bills (a total ..
|
Generate a salary as a number with two digits
: Generate a salary as a number with two digits after the decimal point. The salary for a teacher should be in the range from $40,000 to 70,000.
|
Program to tests whether they form a magic square
: Write a program that reads n2 numbers from standard input and tests whether they form a magic square when put into matrix form.
|
Write a program to print out a simplified bill
: Write a program to print out a simplified bill. The customer's name, the number of hours of labor, and the cost of parts and supplies should be entered in response to INPUT statements.
|
Calculate the average of a variable quantity of integers
: Create a simple command line program to calculate the average of a variable quantity of integers that are passed as an argument when the program is called.
|
Write a program to print all of the permutations
: Write a program to print all of the permutations of the values 1, 2, 3, ..., n - Your program takes one argument from the command line, which as an integer n that is the number of elements.
|
What rules of inference are used in the argument
: What rules of inference are used in the argument? "No man is an island. Manhattan is an island. Therefore, Manhattan is not a man."
|