CrazyEngineers
  • A1. Generation and Ordering in a 2D Array

    1. Dynamically allocate a 2D integer array A of size nXn (n is in the power of 2).
    2. Fill A with random integers in [1, N] which should be all distinct.
    3. 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
    4. Print the elements of A in a file named "a1.txt" so that that the printed sequence is sorted in ascending order.
    [TABLE]
    [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]
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Home Channels Search Login Register