Program to tests whether they form a magic square

Assignment Help C/C++ Programming
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.

Reference no: EM13693811

Questions Cloud

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."

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd