一元多项式
下面程序为什么运行不了?#include <stdio.h>
#include <stdlib.h>
#include <process.h>
typedef struct{
float coef;
int expn;
}Elem;
typedef struct Node{
Elem data;
struct Node *next;
}node, *NodePos;
typedef struct list
{
NodePos head,tail;
int length;
};
int Initlist(struct list *l)
{
l->head=l->tail=(NodePos)malloc(sizeof(node));
if (!l->head)
{
return 0;
exit(-1);
}
l->tail->next=NULL;
l->head->next=l->tail->next;
return 1;
}
int MakeNode(struct list *l,Elem e)
{
NodePos n;
n=(NodePos)malloc(sizeof(node));
if(!n)
{
exit(-1);
return 0;
}
n->data.coef=e.coef;
n->data.expn=e.expn;
l->tail->next=n;
l->tail=n;
l->tail->next=NULL;
l->length++;
return 1;
}
void creatpolyn(struct list *p)
{
int i,expn,m;
float coef;
Elem e;
printf("请输入多项式的项数m=");
scanf("%d",&m);
for (i=1;i<=m;i++)
{
printf("请输入多项式的第%d项的系数:",i);
scanf("%f",&coef);
e.coef=coef;
printf("请输入多项式的第%d项的指数:",i);
scanf("%d",&expn);
e.expn=expn;
MakeNode(p,e);
}
}
void printpolyn(struct list *p)
{
NodePos r;
r=p->head;
while (r !=NULL)
{
printf("%f*X^%d",r->data.coef,r->data.expn);
r=r->next;
}
}
main()
{
struct list *pa;
pa=NULL;
Initlist(pa);
creatpolyn(pa);
printpolyn(pa);
}