Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 503 Solved: 406
[Submit][Status][Web Board]
Description
輸入整數N,輸出相應方陣。
Input
一個整數N。( 0 < n < 10 )
Output
一個方陣,每個數字的場寬爲3。
Sample Input
5
Sample Output
1 1 1 1 1
1 2 2 2 2
1 2 3 3 3
1 2 3 4 4
1 2 3 4 5
HINT
仔細想一想每一行應怎麼表示。
每行:1~行數,(行數+1)個行數。
代碼:
#include <bits/stdc++.h>
using namespace std;
int main(){
int a;
cin>>a;
for(int i=1;i<=a;i++)
{
for(int j=1;j<=i;j++)
{
printf("%3d",j);
}
for(int u=1;u<=a-i;u++)
{
printf("%3d",i);
}
cout<<endl;
}
return 0;
}