Write a program that generates a magic square for an array

Assignment Help Computer Engineering
Reference no: EM132217596

C++ MAGIC SQUARE

write a program that generates a magic square for an array of size 3*3.

step1: use a 2d array of 3*3

step2: fill array with unique values 1-9 genrerated at random (ex. (rand()%9)+1)

use a function to check and see if the random numbers generated have been previously generated in the array,(check for unqiueness)

if the number is unique,store it in your 2d array

step3:display the 2d array

step4:check if thr 2d array is a magic square

(sum of each row=sum of each col.=sum of each diagonal)

step5:keep repeating the loop of steps1-4 until a magic square is found.

EX:

1 2 3

4 5 6

7 8 9

Not magic

2 3 1

4 5 6

7 8 9

not Magic

2 7 6

9 5 1

4 3 8

IS Magic

I CAN'T FIGURE OUT HOW TO OLNY HAVE THE NUMBER USED ONCE IN THE SQURE(NEED TO HAVE NONREPEATING NUMBERS)

#include <iostream>

#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <stdio.h>
using namespace std;
void checkSquare(int a[][3]);

int main()
{
int a[3][3];
srand(time(0));

for (int i=0; i<3; i++)

for (int j=0; j<3;j++)
{

a[i][j]=1+(rand()%9);

}
for (int i=0; i<3; i++)
{
for (int j=0; j<3;j++)

cout<<a[i][j]<<" ";
cout<<endl;

}
}

Reference no: EM132217596

Questions Cloud

Implement a recursive descent parser for a logic calculator : The program should not exit when it encounters an error in the expression. Rather, it should output error information and then accept the next expression.
Explain what needs to be done to defend accounts : Eplain What You Have to do to Defend Accounts. Explain what needs to be done to defend accounts .
Give the associated range of destination host address : Consider a datagram network using 8-bit host addresses, i.e., IP addresses range from 0 to 255.
Write a function max that has two stringparameters : Write an expression that evaluates to true if the value of the string variable s1 is greater than the value of stringvariable s2 .
Write a program that generates a magic square for an array : Use a function to check and see if the random numbers generated have been previously generated in the array,(check for unqiueness)
The method needed to arrange for an object to be notified : The method needed to arrange for an object to be notified when a window's close-window button has been clicked is.
In a company is it good to have a back door account : Having a backdoor account (that is a username/password that can login in to an administrative account on all machines) can be very useful for IT staff.
Accept a variable parameter list of characters and return : Declare an array reference variable, week, and initialize it to an array containing the strings "mon", "tue", "wed", "thu", "fri", "sat", "sun" .
Which of the following is a correct interface : Suppose A is an interface, B is a concrete class with a default constructor that implements A.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Make a visual rendering depicting your design via the use

as the lead software engineer for a medium-sized hospital you have been asked to spearhead an effort to improve the

  Find out what tasks are assigned to each phase

A project includes Analysis, Definition, Design, Implementation, Maintenance, and Support phases. How do we determine what tasks are assigned to each phase.

  Explain any potential ethical issues that could arise

Assignment: SYSTEMS ANALYSIS AND DEVELOPMENT- Identify and describe any potential ethical issues that could arise in connection with the new architecture.

  Evaluatew both local and mean nestlet numbers

Consider laminar flow in a circular tube with a fully developed velocity profile. Let heat be added at a constant rate along the tube from x+ = 0 to X+ = 0.10.

  Discuss encryption can have on incident response activities.

Discuss in your own words the effects that encryption can have on incident response activities.

  Define and initializes three pointers

Display on the screen the addresses stored in those pointers each one in three different forms: octal, decimal and hexadecimal formats.

  Write a function template named maximum

Write a function template named maximum. The function takes two values of the same type as its arguments and returns the larger of the two arguments.

  Difference between mealy and moore state machine

Given the following FIFO and rules, how deep does the FIFO need to be to prevent underflow or overflow?

  Deducing security policy to mitigate the threat.

Information like sales data, client data, and the network configuration. Recognize the threats these significant items are subject to and deduce the security policy in order to mitigate that threat.

  Create a pricing system for a company

Create a pricing system for a company that makes individualized computers, such as you might see on a Web site. There are two kinds of computers.

  How is data encoded and what is the raw transmission speed

Investigate the IEEE FireWire data communication standard. How is data encoded, and what is the raw transmission speed?

  What is an entity relationship diagram

What is an Entity Relationship Diagram. In your answer please describe the terms Entity, Attribute

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