#include<iostream>
#include<iomanip>
using namespace std;
class queue
{
public:
queue(){rear=front=0;}
bool empty(){return rear==front;}
bool get_yanghuisanjiao(int i);
private:
int front;
int rear;
int data[20];
};
int main()
{
queue q;
int y;
cout<<"please put in how many line in yanghuisanjiao"<<endl;
cin>>y;
q.get_yanghuisanjiao(y);
return 0;
}
bool queue::get_yanghuisanjiao(int i)
{
data[0]=1;data[1]=1;//先将第一,第二位置的元素输入;
int h=i;
for(int j=1;j<=i;j++)
{
for(int n=rear;n>=1;n--)
{
data[n]=data[n]+data[n-1];//实现元素的算法;
}
data[rear++]=1;
cout<<setw(h--);
for(int x=0;x<rear;x++)//输出元素;
cout<<" "<<data[x];
cout<<endl;
}
return true;
}
杨辉三角
最新推荐文章于 2024-08-26 21:46:59 发布