【入门】拐角III
Description
输入整数N,输出相应方阵。
Input
一个整数N。( 0 < n < 10 )
Output
一个方阵,每个数字的场宽为3。
Sample Input 1
5
Sample Output 1
5 5 5 5 5 5 4 4 4 4 5 4 3 3 3 5 4 3 2 2 5 4 3 2 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=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%3d",n-arr[i][j]);
}
cout<<endl;
}
return 0;
}
拐角ⅠⅡⅢ都只用改输出这一段的顺序,数组具体内容不变
for(int i=();i();i()){
for(int j=();j();j()){
printf("%3d",());
}
cout<<endl;
}
注:图中中文括号指要改变的内容