Redo the city zone population assignment from Homework 1 with following mandatory modifications:
Assume that the city may have up to N areas (N<=20). Ask the user for the actual number of areas, read their initial populations to a 1D vector array of N used elements, and read the array of coefficient into a 2D matrix array of NxN used elements. Then proceed with calculations as described in the textbook. Also, ask (ie. do not hasrdcode inside the program) for the maximum number of years to run the simulation and how frequently the results should be printed on the screen.
Run your program for N=3 zones and the values provided in the previous assignment. Then run it again for a larger number of zones. Since in the second run you will make up random coefficients that do not correspond to real life the second simulation may result in unpredicted negative values of populations.
A magic square is a NxN matrix in which each of the integers 1, 2, 3, ... N2 appears exactly once and all column sums, row sums, and diagonal sums are equal. For example, the following is a 5x5 magic square in which all the rows, columns and diagonals add up to 65:
| 17 | 24 | 1 | 8 | 15 |
| 23 | 5 | 7 | 14 | 16 |
| 4 | 6 | 13 | 20 | 22 |
| 10 | 12 | 19 | 21 | 3 |
| 11 | 18 | 25 | 2 | 9 |
The following is a procedure for constructing an NxN magic square for any odd integer N. Initialize the array to 0. Place k=1 in the middle of the top row (0, N/2). Then increase k by 1 (k++). Then after integer k has been placed, move up one row and one column to the right (row--; col++) to place the next k, unless one of the following occurs:
This program is more a very good programming exercise that an actual useful program. Run your program at least two times, once for N==5, and once again for a different (odd) size of the magic square.
Make sure that the program proceeds only if you enter an odd number (i.e. N%2!=0). Run your program at least two times, once for N==5, and once again for a different (odd) size of the magic square.
This program is more a very good programming exercise that an actual useful program. This is actually close to Chapter 3, Problem 9, Page 139 for any odd array size N.