帮我看哪错了?多项式问题
#include <stdio.h>#include <stdlib.h>
struct Node
{
float coef;
int expn;
struct Node *next;
}Link;
struct Node *Makenode(struct Node *head)
{
float coef;
int expn;
struct Node *p=NULL;
struct Node *L=head;
p=(struct Node*)malloc(sizeof(Link));
if(!p)
{
printf("分配内存失败!\n");
exit(0);
}
if(head = NULL)
head=p;
else
{
while(L)
{
L=L->next;
}
p->next=L;
L=p;
}
printf("请输入系数:");
scanf("%f",&coef);
//printf("\n");
printf("请输入指数:");
scanf("%d",&expn);
printf("\n");
p->coef=coef;
p->expn=expn;
return head;
}
void printpoly(struct Node *head)
{
struct Node *p=head;
p=p->next;
while(p)
{
// p=p->next;
printf("%fX^%d",p->coef,p->expn);
p=p->next;
}
}
main()
{
int n,i;
struct Node *head=NULL;
printf("请输入项数:");
scanf("%d",&n);
printf("\n");
for(i=1;i<=n;i++)
{
printf("输入第%d项的数据\n",i);
head=Makenode(head);
}
printpoly(head);
}