160417_杨辉三角(pascal's <wbr>triangle)
#include
#include
using namespace std;
int main()
{
const int ROW=13;
#if 1
int a[ROW][ROW];
for (int row = 0; row <<span style=" color:#c0c0c0;"> ROW; ++row) {
for (int column = 0; column <=row; ++column) {
if (column==0||(row==column)) {
a[row][column]=1;
}else {
a[row][column]=a[row-1][column-1]+a[row-1][column];
}
}
}
for (int row = 0; row <<span style=" color:#c0c0c0;"> ROW; ++row) {
for (int column = 0; column <<span style=" color:#c0c0c0;"> (ROW-row); ++column) { //前面空格
printf(" ");
}
for (int column = 0; column <=row; ++column) {
printf("M",a[row][column]);
}
printf("\n");
}
#else
for (int row = 0; row <<span style=" color:#c0c0c0;"> ROW; ++row) {
for (int column = 0; column <<span style=" color:#c0c0c0;"> (ROW-row); ++column) {
printf(" ");
}
for (int column = 0; column <<span style=" color:#c0c0c0;"> 2*row+1; ++column) {
if (column%2==0) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
#endif
cout << "Hello World!" << endl;
return 0;
}
160417_杨辉三角(pascal‘s triangle)
最新推荐文章于 2021-07-22 10:21:05 发布