#K44252. Diagonal Matrix Generation

    ID: 27490 Type: Default 1000ms 256MiB

Diagonal Matrix Generation

Diagonal Matrix Generation

Given an integer (n) and a character (ch), generate an (n \times n) matrix such that the main diagonal is filled with (ch) and all other positions are filled with underscores (''). The main diagonal of a matrix is defined as the set of elements (a{i,i}) for (i=1,2,\dots,n). Your task is to construct and print this matrix.

Example: For input:

4
X

The output should be:

X _ _ _
_ X _ _
_ _ X _
_ _ _ X

inputFormat

Input is given via standard input (stdin) in two lines. The first line contains an integer (n) (the size of the matrix), and the second line contains a single character (ch) used to fill the diagonal.

outputFormat

Print the generated matrix to standard output (stdout). Each of the (n) lines corresponds to a row of the matrix. Each element in a row should be separated by a single space.## sample

4
X
X _ _ _

_ X _ _ _ _ X _ _ _ _ X

</p>