鱼C论坛

 找回密码
 立即注册
查看: 5627|回复: 2

为什么当行数超过11时会出现这种问题

[复制链接]
发表于 2020-11-25 16:21:59 | 显示全部楼层 |阅读模式
8鱼币
#include<stdio.h>
#include<stdlib.h>

#define MAXSIZE 20
typedef struct
{        int datas[MAXSIZE];
        int front,rear;
}SqQueue;

//初始化队
void InitQueue(SqQueue *Q)
{   Q->front=Q->rear=-1;
}
int EmptyQueue_C(SqQueue *Q)
{//若队列为空,返回1,否则返回0
        if(Q->rear==Q->front)        return 1;
        else return 0;
}//EmptyQueue_C

// 取对头元素
char GetQueue_C(SqQueue *Q)
{//若队列不为空,则返回队首元素,否则返回NULL
        int e;
        if(EmptyQueue_C(Q))
            {printf("Queue is empty\n");
                 return(0);}
        else
    {e=Q->datas[(Q->front+1)%MAXSIZE];
             return e;}
}//GetQueue_C

//入队
int EnQueue_C(SqQueue *Q, int e)
{//将元素e插入到队列中,作为新的队尾。操作成功返回1,否则返回0
if(Q->front==(Q->rear+1)%MAXSIZE)//队满
                {printf("Queue is full.\n");
                 return 0;}
        else
                {Q->rear=(Q->rear+1)%MAXSIZE;
                 Q->datas[Q->rear]=e;
                 return 1;}
}//EnQueue_C


//出队
int DeQueue_C(SqQueue *Q)
{  //删除队头元素,若操作成功返回1,否则返回0
if(EmptyQueue_C(Q))
                {printf("Queue is empty.\n");
                 return 0;}
        else
                {Q->front=(Q->front+1)%MAXSIZE;
                 return 1;}       
}//DeQueue_C

//输出队
void PRINT(SqQueue *Q)
{
        int i;
        if(Q->front!=Q->rear)
        {
                printf("当前循环队列中从头到尾的元素为:");
                i=Q->front;
                while(i!=Q->rear)
                {
                        i=(i+1)%MAXSIZE;
                        printf("%d ",Q->datas[i]);                       
                }
        }
        else
                printf("当前循环队列为空!");
        putchar('\n');
}

main()
{
        SqQueue *Q;
        int n;
        int i,j,k,s1,s2;

        Q=(SqQueue *)malloc(sizeof(SqQueue));
       
        InitQueue(Q);

        EnQueue_C(Q,1);
       
printf("请输入杨辉三角的层数:\n");
scanf("%d",&n);
for(k=0;k<n-1;k++)   
       printf(" ");
  printf("1\n");   
  for(i=2;i<=n;i++)
  {   for(k=0;k<n-i;k++)   
       printf(" ");   
    for(j=1,s1=0;j<i;j++)  
    {   int s2;   
            s2=GetQueue_C(Q);
                DeQueue_C(Q);     
                printf("%d",s1+s2);   
                printf(" ");   
                EnQueue_C(Q,s1+s2);  
                s1=s2;
        }  
        printf("1");
        EnQueue_C(Q,1);  
        printf("\n");
  }
}

3.PNG
1.PNG
2.PNG
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-30 06:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表