?? yanghui.cpp
字號:
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -1
typedef int QElemType;
typedef int Status;
#define MAXQSIZE 100
typedef struct{
QElemType * base;
int front;
int rear;
}SqQueue;
//隊列初始化
Status InitQueue(SqQueue &Q)
{
Q.base=(QElemType *)malloc(MAXQSIZE * sizeof(QElemType));
if(!Q.base)exit(OVERFLOW);
Q.front=Q.rear=0;
return OK;
}
//隊列長度
int QueueLength(SqQueue Q)
{
return(Q.rear-Q.front+MAXQSIZE)%MAXQSIZE;
}
//插入隊尾元素
Status EnQueue(SqQueue&Q,QElemType e)
{
if((Q.rear+1)%MAXQSIZE==Q.front)return ERROR;
Q.base[Q.rear]=e;
Q.rear=(Q.rear+1)%MAXQSIZE;
return OK;
}
//刪除對頭元素
Status DeQueue(SqQueue &Q,QElemType &e)
{
if(Q.front==Q.rear)return ERROR;
e=Q.base[Q.front];
Q.front=(Q.front+1)%MAXQSIZE;
return OK;
}
void YangHui(int n)
{
SqQueue Q;
InitQueue(Q);
EnQueue(Q,1);
EnQueue(Q,1);
int s=0,t;
for(int i=1;i<=n;i++)
{
cout<<endl;
EnQueue(Q,0);
for(int j=1;j<=i+2;j++)
{
t=1;
DeQueue(Q,t);
EnQueue(Q,s+t);
s=t;
if(j!=i+2)cout<<s<<' ';
}
}
}
void main()
{
int n;
cout<<"輸入次數:";
cin>>n;
YangHui(n);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -