QAQ每个杨辉三角后面记得加\n
#include <iostream>
using namespace std;
int tri[30][30] = { 1 };
int main()
{
for (auto i = 1; i < 30; ++i)
for (auto j = 0; j < 30; ++j)
tri[i][j] = tri[i - 1][j - 1] + tri[i - 1][j];
int n;
while (cin >> n)
{
if (n == 0)
break;
for (auto i = 0; i < n; ++i)
{
auto j = 0;
while (tri[i][j])
{
cout << tri[i][j] << ' ';
++j;
}
cout.put('\n');
}
cout.put('\n');
}
return 0;
}
送答案:
int main()
{ int i,j,n=0,a[30][30]={0};
while(scanf(“%d”,&n)!=EOF&&n!=0)
{
for(i=0;i<n;i++)
a[i][0]=1;
for(i=1;i<n;i++)
for(j=1;j<=i;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
for(i=0;i<n;i++)
{ for(j=0;j<=i;j++)
if (j<i)
{printf(“%d “,a[i][j]);}
else
{printf(“%d”,a[i][j]);}
printf(“\n”);
}
printf(“\n”);
}
return 0;
}
NGB是什么梗