An element A(i, j) is said to be a diagonal
element if i = j.
Write a program that reads in the order of a square matrix n and
a width value w and reads in and prints out a n x n array of
integers. If the width w is 1 then consider only the elements on the diagonal of
the array. If the width w is 3 then along with the diagonal consider one element to
the right of diagonal and one element to the left of the diagonal, if the elements exists.
In general, according to the width w, consider the (w-1)/2 elements to the right of
the diagonal element and also to the left of the diagonal, if they exist. Now, your task
is to write an internal subroutine Change() to change all these (wide) diagonal elements.
If an element in this (wide) diagonal is odd, double it. If it is even, half it. Display
this new array.
You can assume 0 < w < 2n-1. Also you have to
consider only the elements which exist. An element exists in a row if the column number is
between 1 and the maximum number of columns.
Arrays must be passed using assumed-shaped arrays. You must write an
internal subroutine for the required process of the matrix.
The input to your program has the following form
n w
a11 a12 a13
a1n
a21 a22 a23
a2n
: :
: :
an1 an2 an3
ann
where n and w are the order and width as mentioned
earlier and aij is the INTEGER for row i and column j. For
example, if the input data were:
5 3
1 2 3 4 5
2 3 4 5 6
3 4 6 5 7
4 5 6 7 8
3 4 5 6 7
Then you should print:
2 1 3 4 5
1 6 2 5 6
3 2 3 10 7
4 5 3 14 4
3 4 5 3 14
Hint: For each row, an element lies on the wide diagonal if it lies
between current row number minus the half the width and current row number plus half the
width.
Please follow the same notes posted for last three projects.