Question: C++ Program: In recreational mathematics, a magic square is a n n square matrix (where n is the number of cells on each side) filled
C++ Program:

In recreational mathematics, a magic square is a n n square matrix (where n is the number of cells on each side) filled with distinct positive integers in the range (1,2,...,n2), such that each cell contains a different integer and the sum of the integers in each row, column and diagonal is equal. The sum is called the magic constant or magic sum of the magic square. A square matrix with n cells on each side is said to be of order n. For example, the smallest non-trivial case of a magic square of order 3 is the following: 2|716| 15 915|1|-> 15 4|3|8|-> 15 15 15 15 15 15 a) Write a C++ program that uses a 3 x 3 array and randomly places each integer from 1 to 9 into one of the nine squares. Then, the program calculates the magic number by adding all the numbers in the array and then dividing the sum by 3. Finally, the program outputs the number of times a magic square occurred. Your program must contain the following functions: Function fil!Board that randomly fills the array with numbers from 1 to 9 placed randomly; Function isMagic that determines if the array is a magic square; Function showBoard that prints out the array that is found to be a magic square. b) Run your program for a large number of times such as 1000, 10000, or 1000000, and observe the number of occurrences where the array is a magic square. c) Show that your program runs correctly by running the magic square example provided above
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
