435,346 Members | 2,318 Online
Need help? Post your question and get tips & solutions from a community of 435,346 IT Pros & Developers. It's quick & easy.

# Why won't my code accept output for some values?

 P: 1 I have this program that gets the roots of a polynomial. In the function to get the roots, I have a condition that asks if a certain array element is equal to zero. It works for some input like 2 1,4,4 but not on this one: -2,-1,15 By the way, it also works with other values with a negative sign Plus I see a negative zero in the output. Does it mean anything? Here is the code: http://ideone.com/B4uCm1 I'm thinking that the problem is somewhere around here: Expand|Select|Wrap|Line Numbers int  get_rational_roots_size(int polynomial_degree, double polynomial_coefficients[], double possible_roots[], int num_possible_roots) {     int i, j, num_rational_roots = 0;     double quotient_coefficients[polynomial_degree];       quotient_coefficients[0] = polynomial_coefficients[polynomial_degree];     for(i = 0; i < num_possible_roots; i++)     {         for(j=1;j<=polynomial_degree;j++)         {             quotient_coefficients[j] = (quotient_coefficients[j-1]*possible_roots[i])+polynomial_coefficients[polynomial_degree-j];             if(quotient_coefficients[j] == +0 || quotient_coefficients[j] == -0 && j == 2)             {                 num_rational_roots++;             }         }      }     return num_rational_roots; }   void get_rational_roots(int polynomial_degree, double polynomial_coefficients[], double possible_roots[], int num_possible_roots, double rational_roots[]) {     int i, j, element = 0;     double quotient_coefficients[polynomial_degree];       quotient_coefficients[0] = polynomial_coefficients[polynomial_degree];     for(i = 0; i < num_possible_roots; i++)     {         for(j=1;j<=polynomial_degree;j++)         {             quotient_coefficients[j] = (quotient_coefficients[j-1]*possible_roots[i])+polynomial_coefficients[polynomial_degree-j];             printf("Result %d = %lf\t", j, quotient_coefficients[j]);             if(quotient_coefficients[j] == +0 || quotient_coefficients[j] == -0 && j == 2)             {                 rational_roots[element] = possible_roots[i];                 printf("\nRoot %lf at i = %d, j = %d\n", rational_roots[element], i, j);                 element++;             }         }         printf("\n");     } }   Ohh. And this is not a homework. Thanks :D Oct 19 '15 #1