fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4. #define YES (0 == 0)
  5. #define NO (1 == 0)
  6. #define Polynomial_MaxDegree 100
  7. struct Link{
  8. int exp;
  9. float coef;
  10. struct Link* pNext;
  11. };
  12. typedef struct Link* Poly;
  13. typedef struct Link* pLink;
  14.  
  15. void Polynomial_Print(Poly p){
  16. Poly tmp = p->pNext;
  17. if(tmp==NULL) {
  18. printf("0");
  19. return ;
  20. }
  21. while(tmp!=NULL){
  22. if(tmp==p->pNext)printf("%f*x^%d ", tmp->coef,tmp->exp);
  23. else printf("%+f*x^%d ", tmp->coef,tmp->exp);
  24. tmp = tmp->pNext;
  25. }
  26. }
  27. int main(){
  28. Poly PA;
  29. PA = (pLink)malloc(sizeof(struct Link));
  30. PA->pNext = (pLink)malloc(sizeof(struct Link));
  31. PA->pNext->pNext=NULL;
  32. PA->pNext->coef =3;
  33. PA->pNext->exp =2;
  34. Polynomial_Print(PA);
  35. return 0;
  36. }
Success #stdin #stdout 0s 5036KB
stdin
Standard input is empty
stdout
3.000000*x^2