输入一个整数n(1<n<10),在屏幕上显示数字三角形。例如,n=5,显示:
1
121
12321
1234321
123454321
#include<iostream>
using namespace std;
int main() {
int a, i = 0, j = 0, max = 0;
cin>>a;
cout<<"n="<<a<<"\n";
for (i = 1; i <= 2 * a - 1; i++) {
if (i <= a)
//前半段
max++;
else break;
for (j = 1; j <= 2 *max -1 ; j++) {
if (j <= max)
cout<< j;
else
cout<< max*2-j;
}
cout<<"\n";
}
return 0;
}