//chỉ thêm Poly nếu hệ số khác 0
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct Polynom
{
int coeff;
int pow;
struct Polynom *link;
}Poly;
Poly *createnode(int coeff, int pow)
{
Poly *node=(Poly*)malloc(sizeof(Poly));
if(node==NULL) return NULL;
node->coeff=coeff;
node->pow=pow;
node->link=NULL;
return node;
}
void addTail(Poly* first,Poly *temp)
{
if(first==NULL) first=temp;
Poly *p=first;
while(p!=NULL)
p=p->link;
p->link=temp;
}
void createPoly(Poly *first)
{
Poly *temp;
int n,i,x;
printf("\nBac cua da thuc: ");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf("\nHe so cua x^%d: ",i);
scanf("%d",&x);
if(x!=0)
{
temp=createnode(x,i);
addTail(first,temp);
}
}
printf("\n");
}
void printPoly(Poly *first)
{
if(first==NULL) return;
Poly* temp;
temp=first;
while(temp!=NULL)
{
printf("%d;%d ",temp->coeff,temp->pow);
temp=temp->link;
}
}
int main()
{
Poly* first=NULL;
createPoly(first);
printPoly(first);
getch();
}