Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. int readPoly(int coeff[], int degree)
  2. {
  3. int x=degree;
  4. char current;
  5. int currentcoeff;
  6. int nextcoeff;
  7. int exponent;
  8.  
  9. while(x>0)
  10. {
  11. if(scanf("%d",&currentcoeff)!=EOF)
  12. {
  13. if(scanf("%d",&nextcoeff)==1)
  14. {
  15. printf("n coeff is %d",nextcoeff);
  16. }
  17. else if(scanf("%c",&current)==1 && current=='x')
  18. {
  19. if(scanf("%c",&current)==1 && current=='^')
  20. {
  21. scanf("%d",&exponent);
  22. x--;
  23. printf("exp");
  24. continue;
  25. }
  26. else
  27. {
  28. exponent = 1;
  29. }
  30. }
  31. else
  32. {
  33. exponent = 0;
  34. x--;
  35. continue;
  36. }
  37. }
  38. else if(scanf("%c",&current)==1)
  39. {
  40. if(current=='+')
  41. {
  42. if(scanf("%d",&currentcoeff)==1)
  43. {
  44. if(scanf("%c",&current)==1 && current=='x')
  45. {
  46. if(scanf("%c",&current)==1 && current=='^')
  47. {
  48. scanf("%d",&exponent);
  49.  
  50. }
  51. else
  52. {
  53. exponent = 1;
  54. }
  55. }
  56. else
  57. {
  58. exponent = 0;
  59. }
  60.  
  61. }
  62. else
  63. {
  64. scanf("%c",&current);
  65. if(scanf("%c",&current)==1 && current=='^')
  66. {
  67. scanf("%d",&exponent);
  68. }
  69. }
  70. }
  71. else if(current=='x')
  72. {
  73. if(scanf("%c",&current)==1 && current=='^')
  74. {
  75. currentcoeff = 1;
  76. scanf("%d",&exponent);
  77. }
  78. else
  79. {
  80. currentcoeff = 1;
  81. exponent = 1;
  82. }
  83. }
  84. else{}
  85. }
  86. printf("\n%d is coeff",currentcoeff);
  87. printf("\n%d is exponent\n",exponent);
  88. x--;
  89. }
  90. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement