C语言123exe,这个程序为什么输入第一个数字后就提示已123.exe(我的程序名)停止工作?...

已结贴√

问题点数:20 回复次数:10

ca56232b3bbedf9a539d07f37fffb99a.gif

3144d8b7615c79d9f638db40d5689d26.gif

a218af6549b45ee526caf607ebff1358.gif

0f8df0e29816ae721419de940fb833d1.gif

这个程序为什么输入第一个数字后就提示已123.exe(我的程序名)停止工作?

//*两个多项式的输入必须依照幂次数的升序依次输入*//

#include

#include

#include

#define LENTH sizeof(struct  Polyfactor)

#define NULL 0

typedef struct Polyfactor                       //*构造多项式因子*//

{

int coeff;                        //*多项式因子的系数*//

int power;                       //*多项式因子的幂次数*//

struct Polyfactor *next;       //*用于指向下一个多项式因子的指针*//

};

struct Polyfactor *createpolyn(struct Polyfactor *head)     //*建立链表存储多项式*//

{

struct Polyfactor *p1=NULL;                 //*设置两个指针用于创建链表*//

struct Polyfactor *p2=NULL;

int m=0;

int n=0;

while(m!='q'&&n!='q')                   //*当输入不是数字时多项式输入结束*//

{

printf("请输入多项式因子的系数:");

scanf("%d\n",m);

printf("请输入多项式因子的幂次数:");

scanf("%d\n",n);

if(head=NULL)

{

p1=(struct Polyfactor*)malloc(LENTH);

if(p1==NULL)

{exit(0);}

head=p1;

p2=p1;

}

else

{

p1=(struct Polyfactor*)malloc(LENTH);

if(p1==NULL)

{exit(0);}

else

{

p2->next=p1;

p2=p1;

}

p2->coeff=m;

p2->power=n;

}

}                            //*多项式的输入*//

return head;

}

struct Polyfactor *addpolyn(struct Polyfactor *head,struct Polyfactor *p1,struct Polyfactor *p2,struct Polyfactor *p3)    //*对链表进行插入,其中p3指向P1的前驱*//

{

if(p1->powerpower)                   //p1所指向的链表结点的幂次数比p2的小时,将p2插入p1后*//

{

p2->next=p1->next;

p1->next=p2;

}

else                                      //p1所指向的链表结点的幂次数比p2的大时,将p2插入p1前*//

{

p2->next=p1;

p3->next=p2;

}

return head;

}

struct Polyfactor *delpolyn(struct Polyfactor *head,struct Polyfactor *p1,struct Polyfactor *p3)               //*对链表进行删除,其中P3指向要删除点的前驱*//

{

p3->next=p1->next;                                     //*把要删除点的后继赋值给删除点的前驱的后继*//

return head;

}

void main()

{

struct Polyfactor *p,*p1,*p2,*p3=NULL;

struct Polyfactor *head1=NULL,*head2=NULL;

struct Polyfactor *createpolyn(struct Polyfactor *head1);

struct Polyfactor *addpolyn(struct Polyfactor *head,struct Polyfactor *p1,struct Polyfactor *p2,struct Polyfactor *p3);

struct Polyfactor *delpolyn(struct Polyfactor *head,struct Polyfactor *p1,struct Polyfactor *p3);

head1=p1=createpolyn(head1);                   //*创建两个链表分别把两个头指针赋值给head1和head2*//

head2=p2=createpolyn(head2);

do

{

if(p1->power==p2->power)                        //*两个多项式因子的幂次数相同*//

{

if(p1->coeff==p2->coeff)

{

head1=delpolyn(head1,p1,p3);

}

else

{

p1->coeff+=p2->coeff;

}

}

else                                          //*两个多项式的幂次数不同*//

{

head1=addpolyn(head1,p1,p2,p3);

}

p3=p1;

p1=p1->next;

p2=p2->next;

}while(p1&&p2);                             //*当两个链表都还没指向链表结尾时*//

while(p2)

head1=addpolyn(head1,p1,p2,p3);

p=head1;

do

{

printf("%dX^%d",p->coeff,p->power);

printf("+");

p=p->next;

}while(p);                                    //*输出所得多项式的结果*//

}

这个程序为什么输入第一个数字后就提示已123.exe(我的程序名)停止工作?

搜索更多相关主题的帖子:

数字 提示 输入

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值