Question: Write a C++ program that : 1. Allow the user to enter the size of the square such as N. N must be greater than

Write a C++ program that : 1. Allow 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. 3. Use function to Populate the array with distinct random numbers that are between 1 - 100 4. Use a function to determine whether the numbers in n x n array are magic square numbers. 5. Repeat steps 1 4 until the user terminates the program

Formula used to find the Magic Number: n*(n^2+1)/2

OUTPUT

Enter the size of the magic square : 3

The magic sequence that is created for the 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 Column # 1 = 15

Sum of numbers in Column # 2 = 15

Sum of numbers in Column # 3 = 15

Sum of numbers in first diagonal = 15

Sum of numbers in second diagonal = 15

The above is magic square

Would like to find another magic square - Enter y or Y for yes or n | N for no y Enter the size of the magic square : 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!