Computers and Technology
Computers and Technology, 10.09.2019 19:10, tbiles99

An x n matrix that is filled with the numbers 1, 2, 3, n² 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.
implement the following algorithm to construct the magic n-by-n squares. this algorithm works only if n is odd.
place a 1 in the middle of the bottom row.
after k has been placed in the (i, j) square, place k+1 into the square to the right and down, wrapping around the borders.
however, if the square to the right and down has already been filled, or if you are in the lower right corner, then you must move to the square straight up (from the last square that you were on) instead.
skeleton:
# populate a 2-d list with numbers from 1 to n2
def make_square ( n ):
# print the magic square in a neat format where the numbers
# are right justified
def print_square ( magic_square ):
# check that the 2-d list generated is indeed a magic square
def check_square ( magic_square ):
def main():
# prompt the user to enter an odd number 3 or greater
# check the user input
# create the magic square
# print the magic square
# verify that it is a magic square
main()
in your function main() you will prompt the user to enter an odd number. you must check that the input is a positive odd number greater than or equal to 3. if it is not, you will prompt the user to re-enter the number and check again and again.
then you will create a 2-d list representing the magic square. you will then print out the magic square in a neat format by calling the function in the function print_square() you must use print with formatting.
you will then call the function this function checks that the sum of all the rows have the same value and prints out that sum. it checks that the sum of all the columns have the same value and prints out that sum. it sums the two main diagonals and prints out the sum. for a magic square of size n, the sum is n * (n2 + 1) / 2.
this is a sample of what the program will output:
enter an odd number: 5
here is a 5 x 5 magic square:
11 18 25 2 9
10 12 19 21 3
4 6 13 20 22
23 5 7 14 16
17 24 1 8 15
sum of row = 65
sum of column = 65
sum diagonal (ul to lr) = 65
sum diagonal (ur to ll) = 65

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 14:50, williamsgregg5214
Drag each label to the correct location on the image list the do’s and don’ts of safeguarding your password. a. keep yourself logged in when you leave your computer. b. don’t write your password down and leave it where others can find it. c. share your password with your friends. d.each time you visit a website, retain the cookies on your computer. e. use a long password with mixed characters.1. do's 2. don'ts
Answers: 2
image
Computers and Technology, 22.06.2019 23:30, TheBurntToast
What is the digital revolution and how did it change society? what are the benefits of digital media?
Answers: 1
image
Computers and Technology, 23.06.2019 02:50, CrusaderLord
Define a class named movie. include private fields for the title, year, and name of the director. include three public functions withprototypes void movie: : settitle(cstring); , voidmovie: : setyear(int); , void movie: : setdirector(string); . includeanother function that displays all the information about a movie. write a main() function that declares a movie object namedmyfavoritemovie. set and display the object's fields. this is what i have but know its wrong since it will notcompile: #include#includeusing namespace std; //class declarationclass movie{private: string movietitle ; string movieyear; string directorname; public: void settitle(string title); void setyear(string year); void setdirector(string director); void displayinfo(); }; //class implementationvoid movie: : settitle(string title){ movietitle = title; cout< < "what is the title of themovie? "< > temp; myfavoritemovie. settitle(temp); cout< < "enter movie year"< > temp; myfavoritemovie. setyear(temp); cout< < "enter director'sname"< > temp; myfavoritemovie. setdirector(temp); //display all the data myfavoritemovie. displayinfo(); system("pause"); return 0; this code is not entirely mine someone on cramster edited my firstcode but then i try manipulating the new code and i still get acompile error message : \documents\visual studio 2008\projects\movie\movie\movie. cpp(46) : error c2679: binary '< < ' : no operator found which takes aright-hand operand of type 'std: : string' (or there is no acceptableconversion)c: \program files (x86)\microsoft visual studio9.0\vc\include\ostream(653): could be'std: : basic_ostream< _elem,_traits> & std: : operator< < > (std: : basic_ostream< _elem,_traits> & ,const char *)w
Answers: 1
image
Computers and Technology, 23.06.2019 03:50, dondre54
Q-1 which of the following can exist as cloud-based it resources? a. physical serverb. virtual serverc. software programd. network device
Answers: 1
Do you know the correct answer?
An x n matrix that is filled with the numbers 1, 2, 3, n² is a magic square if the sum of the eleme...

Questions in other subjects: