fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct Polynomial
  4. {
  5. int pow;
  6. int cons;
  7. struct Polynomial *next;
  8. }poly;
  9. poly *start;
  10. void create(int p, int c)
  11. {
  12. poly *a=NULL;
  13. a=(poly*)malloc(sizeof(poly));
  14. a->pow=p;
  15. a->cons=c;
  16. a->next=NULL;
  17. if(start==NULL)
  18. start=a;
  19. else
  20. {
  21. poly *n=start;
  22. while(n->next!=NULL);
  23. n->next=a;
  24. }
  25. }
  26. void display()
  27. {
  28. if(start==NULL)
  29. {
  30. printf("List is empty.");
  31. return;
  32. }
  33. else
  34. printf("%dx^%d ",start->cons,start->pow);
  35. for(poly *n=start->next;n!=NULL;n=n->next)
  36. printf("+ %dx^%d ",start->cons,start->pow);
  37. }
  38. int main()
  39. {
  40. int i=1,a,b;
  41. while(i!=0)
  42. {
  43. printf("Input 1 to input a polynomial, 2 to display, 3 to exit.");
  44. scanf("%d",&i);
  45. switch(i)
  46. {
  47. case 1:
  48. printf("Polynomial constant and power?");
  49. scanf("%d%d",&a,&b);
  50. create(b,a);
  51. break;
  52. case 2:
  53. display();
  54. break;
  55. case 3: i=0;
  56. break;
  57. default:
  58. printf("Wrong Input.");
  59. i=1;
  60. }
  61. }
  62. }
Time limit exceeded #stdin #stdout 5s 9432KB
stdin
Standard input is empty
stdout
Standard output is empty