对角线2输入整数N,输出相应方阵

 

对角线2

题目描述
输入整数N,输出相应方阵。
输入
一个整数N。( 0 < n < 10 )
输出
一个方阵,每个数字的场宽为3。
样例:
输入
5
输出
 0  0  0  0  1
 0  0  0  1  0
 0  0  1  0  0
 0  1  0  0  0
 1  0  0  0  0

 


#include <iostream>
#include <algorithm>
#include<cstring>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n][n];
    for(int i=1;i<=n;i++){
        for(int j=n;j>=1;j--){
            if(i==j){
                cout<<setw(3)<<"1";
            }
            else{
                cout<<setw(3)<<"0";
            }
        }
        cout<<endl;
    }
    return 0;
}