#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n;
cout << "please enter the line you want(MAX=30):" << endl;
cin >> n;
int a[30][30];
for (int i = 0; i < n; i++)
{
a[i][0] = 1;
a[i][i] = 1;
}
for (int i = 1; i < n; i++)
{
for (int j = 1; j < i; j++)
{
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
}
for (int i = 0; i < n; i++)
{
for (int k = 0; k < n-i; k++)
cout <<" ";
for (int j = 0; j <= i; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
[c++]杨辉三角
最新推荐文章于 2025-07-08 07:40:01 发布