C++ Zig Zag Matrix
Define a 2D array matrix, the size of
which is 4x4. Initialize this 2D array using random numbers in the
range of [10, 99]. After finishing the initialization, display
the matrix in the command line window.
Then program needs an extra function
rearrange(), which rearranges this 2D
array based on a zig zag order like below:
For example, if the initialized matrix is:
This should be the resulting matrix:
Specifically, the function rearrange()
uses a pointer that points matrix as a
parameter. Plus, this function must return void. The main program
outputs the resulting matrix.
Inside rearrange(), the program needs
to traverse the original matrix from top to bottom (row by row),
and for each row, it needs to traverse from left to right (column
by column) so it can get an array. But, it needs to write such
an array into a resulting matrix using the zig zag pattern.
Requirement: When accessing the element in
the 2D array, the program must use pointer. NO
USE index like matrix[j]
instead. Avoid using advanced syntax.
Hint: Considering the 2D array is
small, the program does not need to use loop inside
rearrange(). Enumerate each mapping
relationship between a cell in the original matrix and the
corresponding cell in the resulting matrix.
C++ Zig Zag Matrix Define a 2D array matrix, the size of which is 4x4. Initialize this 2D array using random numbers in
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
C++ Zig Zag Matrix Define a 2D array matrix, the size of which is 4x4. Initialize this 2D array using random numbers in
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!