Advertisement
Guest User

asd

a guest
Feb 21st, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. Polinomio& operator-(const Polinomio& a, const Polinomio& b)
  2. {
  3. Polinomio resta;
  4. if (a.cantidad > b.cantidad)
  5. {
  6. for (int i = 0; i < a.cantidad; i++)
  7. {
  8. if (resta.coeficientes[i] == 0)
  9. {
  10. if (a.coeficientes[i] != 0 && b.coeficientes[i] != 0)
  11. {
  12. if (a.exponentes == b.exponentes)
  13. {
  14. resta.coeficientes[i] = a.coeficientes[i] - b.coeficientes[i];
  15. resta.exponentes[i] = a.exponentes[i];
  16. }
  17. else
  18. {
  19. resta.coeficientes[i] = a.coeficientes[i];
  20. resta.coeficientes[i + 1] = b.coeficientes[i];
  21. resta.exponentes[i] = a.exponentes[i];
  22. resta.exponentes[i + 1] = b.exponentes[i];
  23. }
  24. }
  25. else if (a.coeficientes[i] != 0 && b.coeficientes[i] == 0)
  26. {
  27. resta.coeficientes[i] = a.coeficientes[i];
  28. resta.exponentes[i] = a.exponentes[i];
  29. }
  30. }
  31. }
  32. }
  33. else
  34. {
  35. for (int i = 0; i < b.cantidad; i++)
  36. {
  37. if (resta.coeficientes[i] == 0)
  38. {
  39. if (a.coeficientes[i] != 0 && b.coeficientes[i] != 0)
  40. {
  41. if (a.exponentes[i] == b.exponentes[i])
  42. {
  43. resta.coeficientes[i] = a.coeficientes[i] - b.coeficientes[i];
  44. resta.exponentes[i] = a.exponentes[i];
  45. }
  46. else
  47. {
  48. resta.coeficientes[i] = a.coeficientes[i];
  49. resta.coeficientes[i + 1] = b.coeficientes[i];
  50. resta.exponentes[i] = a.exponentes[i];
  51. resta.exponentes[i + 1] = b.exponentes[i];
  52. }
  53. }
  54. else if (a.coeficientes[i] == 0 && b.coeficientes[i] != 0)
  55. {
  56. resta.coeficientes[i] = b.coeficientes[i];
  57. resta.exponentes[i] = b.exponentes[i];
  58. }
  59. }
  60. }
  61. }
  62. int cont = 0;
  63. for (int i = 0; i < 30; i++)
  64. {
  65. if (resta.coeficientes[i] != 0)
  66. {
  67. cont++;
  68. }
  69. }
  70. resta.cantidad = cont;
  71. resta.ordenar_Polinomio();
  72. return resta;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement