C语言 请帮忙看看这个问题
来源:百度知道 编辑:UC知道 时间:2024/05/30 07:42:34
#include <stdio.h>
#include "malloc.h"
typedef struct polyn
{
float coef;
int expn;
polyn* next;
} L_node,*Link_list;
Link_list Pa,Pb;
void CreatPolyn ( )
{
Link_list p,q;
int expn;
int coef;
p = ( Link_list ) malloc ( sizeof( L_node ) );
Pa = p,q=p;
scanf("%d,%d",&coef,&expn);
if(coef == 0) printf("the Polyn is not exist!");
while( coef )
{
p = ( Link_list ) malloc ( sizeof( L_node ) );
q->next =p;
p->coef = coef;
p->expn = expn;
scanf("%f,%d",&coef,&expn);
}
p->next = 0;
}
void display_Polyn ( Link_list p )
{
while(p)
{ p=p->next;
printf ( " %d x exp %d + \n" , p->coef,p-&
#include "malloc.h"
typedef struct polyn
{
float coef;
int expn;
polyn* next;
} L_node,*Link_list;
Link_list Pa,Pb;
void CreatPolyn ( )
{
Link_list p,q;
int expn;
int coef;
p = ( Link_list ) malloc ( sizeof( L_node ) );
Pa = p,q=p;
scanf("%d,%d",&coef,&expn);
if(coef == 0) printf("the Polyn is not exist!");
while( coef )
{
p = ( Link_list ) malloc ( sizeof( L_node ) );
q->next =p;
p->coef = coef;
p->expn = expn;
scanf("%f,%d",&coef,&expn);
}
p->next = 0;
}
void display_Polyn ( Link_list p )
{
while(p)
{ p=p->next;
printf ( " %d x exp %d + \n" , p->coef,p-&
#include <stdio.h>
#include "malloc.h"
typedef struct polyn
{
float coef;
int expn;
struct polyn* next;
} L_node,*Link_list;
Link_list Pa,Pb;
void CreatPolyn ( )
{
Link_list p,q;
int expn;
float coef;//int coef,修改定义为浮点数
p = ( Link_list ) malloc ( sizeof( L_node ) );
Pa = p,q=p;
scanf("%f,%d",&coef,&expn); //%d改为%f
if(coef == 0) printf("the Polyn is not exist!");
while( coef )
{
p = ( Link_list ) malloc ( sizeof( L_node ) );
q->next =p;
p->coef = coef;
p->expn = expn;
q=p;//这句关键,要指向最新的节点,否则将无法形成链表
scanf("%f,%d",&coef,&expn);
}
p->next = NULL;
}
void display_Polyn ( Link_list p )
{
while((p->next)!=NULL) //这里改一下,因为最后一个节点的next已经是NULL,