#K6911. Generate Diagonal Matrix
Generate Diagonal Matrix
Generate Diagonal Matrix
You are given an integer \( n \) and a list of \( n \) integers representing the diagonal values of an \( n \times n \) matrix. Your task is to create such a matrix where all the non-diagonal elements are zeros. More formally, if the given list is \( diag\_values = [d_1, d_2, \ldots, d_n] \), then the resulting matrix \( M \) should satisfy:
\( M_{i,j} = \begin{cases} d_i & \text{if } i = j, \\ 0 & \text{if } i \neq j. \end{cases} \)
You need to construct the matrix and output it in the specified format.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains an integer \( n \), the size of the matrix.
- The second line contains \( n \) space-separated integers representing the diagonal elements.
outputFormat
Output the \( n \times n \) matrix to standard output (stdout). Each of the \( n \) lines should contain \( n \) space-separated integers. Ensure there is no extra space at the end of each line.
## sample3
2 5 7
2 0 0
0 5 0
0 0 7
</p>