探索1
#include <iostream>
#define N 15
using namespace std;
int a[N]={1};
void yanghui(int n)
{
int i,j;
for(i=0;i<n;i++)
{ for(j=0;j<=i;j++) cout<<a[j]<<" ";
cout<<"\n";
for(j=1;j<=i;j++) a[j]+=a[j-1];
}
}
int main()
{
int i,j,n;
cin>>n; yanghui(n);
return 0;
}
#include <iostream>
#define N 15
using namespace std;
int a[N]={1};
void yanghui(int n)
{
int i,j;
for(i=0;i<n;i++)
{ for(j=0;j<=i;j++) cout<<a[j]<<" ";
cout<<"\n";
for(j=1;j<=i+1;j++) a[j]+=a[j-1];
}
}
int main()
{
int i,j,n;
cin>>n; yanghui(n);
return 0;
}
yanghui杨辉三角--(一维数组)探索1 2
时间: 2024-10-01 03:55:15