-->
当前位置:首页 > 题库

PROGRAMMING:Building a matrix

Luz5年前 (2021-05-10)题库485
Enter the integer n (2 ≤ n ≤ 10) to construct an n × N, the outer ring element is 1, the inner element is 0, and the main diagonal and sub diagonal elements are 2. Output the constructed matrix.
###Input format:
Enter n.
###Output format:
n × The matrix of n.
Each number is followed by a space of N lines.
###Input sample 1:
```in
six
```
###Output sample 1:
```out
2 1 1 1 1 2
1 2 0 0 2 1
1 0 2 2 0 1
1 0 2 2 0 1
1 2 0 0 2 1
2 1 1 1 1 2
```
###Input sample 2:
```in
nine
```
###Output sample 2:
```out
2 1 1 1 1 1 1 1 2
1 2 0 0 0 0 0 2 1
1 0 2 0 0 0 2 0 1
1 0 0 2 0 2 0 0 1
1 0 0 0 2 0 0 0 1
1 0 0 2 0 2 0 0 1
1 0 2 0 0 0 2 0 1
1 2 0 0 0 0 0 2 1
2 1 1 1 1 1 1 1 2
```






answer:If there is no answer, please comment