Description
输入整数N,输出相应方阵。
Input
一个整数N。( 0 < n < 10 )
Output
一个方阵,每个数字的场宽为3。
Sample Input 1
5
Sample Output 1
5 4 3 2 1
4 4 3 2 1
3 3 3 2 1
2 2 2 2 1
1 1 1 1 1
Source
二维数组
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n;
cin>>n;
int arr[n][n]={0};
int i=0,j=0;
while(i<n){
j=i;
while(j<n){
arr[i][j]=i;
j++;
}
j=i;
while(j<n){
arr[j][i]=i;
j++;
}
i++;
}
for(int i=n-1;i>=0;i--){
for(int j=n-1;j>=0;j--){
printf("%3d",arr[i][j]+1);
}
cout<<endl;
}
return 0;
}