A Tricky question-write program
A1. Generation and Ordering in a 2D Array
[TR]
[TD]A11[/TD]
[TD]A12[/TD]
[/TR]
[TR]
[TD]A21[/TD]
[TD]A22
[/TD]
[/TR]
[/TABLE]
User input: n, N (≥ n[SUP]2[/SUP]).
An example with n = 4 & N=28:
[TABLE]
[TR]
[TD]2[/TD]
[TD]3[/TD]
[TD]7[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]6[/TD]
[TD]10[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]16[/TD]
[TD]21[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD]19[/TD]
[TD]26[/TD]
[TD]27
[/TD]
[/TR]
[/TABLE]
- Dynamically allocate a 2D integer array A of size nXn (n is in the power of 2).
- Fill A with random integers in [1, N] which should be all distinct.
- Rearrange the elements of A as follows. Let A11, A12, A21, A22 be four mutually disjoint subarrays of A, each of size n/2 x n/2 (figure below). Then A11<A12<A21<A22. If each of these subarrays is recursively splitted into four equal-sized subarrays, then also the property holds.
- Print the elements of A in a file named "a1.txt" so that that the printed sequence is sorted in ascending order.
[TR]
[TD]A11[/TD]
[TD]A12[/TD]
[/TR]
[TR]
[TD]A21[/TD]
[TD]A22
[/TD]
[/TR]
[/TABLE]
User input: n, N (≥ n[SUP]2[/SUP]).
An example with n = 4 & N=28:
[TABLE]
[TR]
[TD]2[/TD]
[TD]3[/TD]
[TD]7[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]6[/TD]
[TD]10[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]16[/TD]
[TD]21[/TD]
[TD]25[/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD]19[/TD]
[TD]26[/TD]
[TD]27
[/TD]
[/TR]
[/TABLE]
0