Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Polinomio& operator-(const Polinomio& a, const Polinomio& b)
- {
- Polinomio resta;
- if (a.cantidad > b.cantidad)
- {
- for (int i = 0; i < a.cantidad; i++)
- {
- if (resta.coeficientes[i] == 0)
- {
- if (a.coeficientes[i] != 0 && b.coeficientes[i] != 0)
- {
- if (a.exponentes == b.exponentes)
- {
- resta.coeficientes[i] = a.coeficientes[i] - b.coeficientes[i];
- resta.exponentes[i] = a.exponentes[i];
- }
- else
- {
- resta.coeficientes[i] = a.coeficientes[i];
- resta.coeficientes[i + 1] = b.coeficientes[i];
- resta.exponentes[i] = a.exponentes[i];
- resta.exponentes[i + 1] = b.exponentes[i];
- }
- }
- else if (a.coeficientes[i] != 0 && b.coeficientes[i] == 0)
- {
- resta.coeficientes[i] = a.coeficientes[i];
- resta.exponentes[i] = a.exponentes[i];
- }
- }
- }
- }
- else
- {
- for (int i = 0; i < b.cantidad; i++)
- {
- if (resta.coeficientes[i] == 0)
- {
- if (a.coeficientes[i] != 0 && b.coeficientes[i] != 0)
- {
- if (a.exponentes[i] == b.exponentes[i])
- {
- resta.coeficientes[i] = a.coeficientes[i] - b.coeficientes[i];
- resta.exponentes[i] = a.exponentes[i];
- }
- else
- {
- resta.coeficientes[i] = a.coeficientes[i];
- resta.coeficientes[i + 1] = b.coeficientes[i];
- resta.exponentes[i] = a.exponentes[i];
- resta.exponentes[i + 1] = b.exponentes[i];
- }
- }
- else if (a.coeficientes[i] == 0 && b.coeficientes[i] != 0)
- {
- resta.coeficientes[i] = b.coeficientes[i];
- resta.exponentes[i] = b.exponentes[i];
- }
- }
- }
- }
- int cont = 0;
- for (int i = 0; i < 30; i++)
- {
- if (resta.coeficientes[i] != 0)
- {
- cont++;
- }
- }
- resta.cantidad = cont;
- resta.ordenar_Polinomio();
- return resta;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement