Question: C++ Program EXAMPLE (Thanks in advance) 1. Prompt the user to enter the size of the square such as N. N must be greater than
C++ Program EXAMPLE (Thanks in advance)
1. Prompt the user to enter the size of the square such as N. N must be greater than or equal to 2 and less than or equal to 10.
2. create an array of size N x N. (the array size must be the size of the user input)
3. use the fucntion to popuate the array with distinct random numbers that are between 1 - 100. (when displaying the array of numbers the numbers should display at random)
4. use a function to determine whether the numbers in N x N are magic square numbers. using the formula (n(n2 + 1)/2
5. repeat steps 1 - 4 until the user termiates the program.
FOR EXAMPLE the program must display rows and colums SUCH THAT all equate to the same sum. If the user enters the size of the array to be 3, the ouput should display numbers that are random(RANDOM NUMBERS BETWEEN 1 - 100), but also add up equally(row and col) to a common number. In the ouput below, each row and column add up to 15. This process should be able to process from number (n range is from >=2 and <= 10).
SAMPLE OUTPUT AS REFERENCE (***NOTE: EVERYTHING IN BOLD SHOULD BE SHOWN IN THE OUTPUT, AND THE NORMAL FONT SHOULD BE A PROMPT/INPUT***)
(input) Enter the size of the magic square: 3
(output)
The magic sequence created for size 3 :
8 1 6
3 5 7
4 9 2
The magic number is 15
Sum of numbers in row #1: 15
Sum of numbers in row #2: 15
Sum of numbers in row #3: 15
Sum of numbers in col #1: 15
Sum of numbers in col #2: 15
Sum of numbers in col #3: 15
Sum of numbers in first diagonal: 15
Sum of numbers in second diagonal: 15
The above is a magic square
Would you like to find another magic square? Enter 'Y' or 'y' for yes or 'N' or 'n' for no: Y (assuming the user chooses y, then repeat the steps)
Enter the size of the magic square: 2 (if the user inputs 2)
(output)
The magic sequence created for size 2 :
1 3
2 4
The magic number is 5
Sum of numbers in row #1 : 4
Sum of numbers in row #2 : 6
Sum of numbers in col #1 : 3
Sum of numbers in col #2 : 7
Sum of numbers in first diagonal: 5
Sum of numbers in second diagonal: 5
The above is not a magic square
Would you like to find another magic square? Enter 'Y' or 'y' for yes or 'N' or 'n' for no: Y (assuming the user chooses y, then repeat the steps)
Enter the size of the magic square : -1
Must be >= 2 & <= 10
Would you like to find another magic square? Enter 'Y' or 'y' for yes or 'N' or 'n' for no: Y (assuming the user chooses y, then repeat the steps
Enter the size of the magic square: k (asuming the user chooses letter 'k')
Invalid choice, must use Y, y, N, n
Would you like to find another magic square? Enter 'Y' or 'y' for yes or 'N' or 'n' for no: N (if the user chooses n, then terminate the program)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
