[ad_1]
Given a small square piece of paper, it can be folded horizontally and they vertically as shown in the figure:
Let N be a positive even number. Imagine an N x N square matrix. The matrix can also be folded the way it was described above. The folded piece of matrix we thus obtain is what we shall call the ‘Quarter matrix’.
For example consider this matrix:
By folding it horizontally (over the axis passing through the middle) we get:
(notice: 3 + 0 = 3; 4 + 4 = 11; 4 + 6 = 10; etc..)
By folding it vertically (over the axis passing through the middle) finaly we get the quarter matrix:
9 15 12 20
9 18 18 11
3 11 22 20
16 13 16 11
Write a C program that scans an N x N matrix (N is even) from the user and outputs the elements of the quarter matrix.
Example 1:
Input:
8
1 1 0 0 0 -1 -1 1
-1 -1 0 -1 -1 -1 1 -1
-1 1 -1 1 -1 0 0 -1
1 -1 1 1 0 0 0 1
0 -1 1 -1 0 1 1 0
0 1 -1 1 0 1 -1 0
0 0 0 -1 1 -1 0 0
-1 0 0 -1 0 -1 0 1
Where: 8 is the order of the matrix N
elements of the matirx.
Output:
0 -1 1 -1
0 1 -1 1
0 0 0 -1
-1 0 0 -1
Explanation: Self evident.
[ad_2]