Thanks for replying
I tested row27 to row 50 with a simpler code
and the roots were correct according to my calculator
root = 1.167304
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <stdio.h>
#include <math.h>
int main()
{
double a=-0.5, b=1.5, c, fa, fb, fc;
fa = pow(a, 5.0) - a - 1;
fb = pow(b, 5.0) - b - 1;
while( fa * fb < 0 )
{
c = (a+b)/2;
fc = pow(c, 5.0) - c - 1;
if(fabs( fc ) < 1e-9)
{
break;
}
else if ( fabs( fc )> 0&&fc*fb < 0 )
{
a = c;
}
else if ( fabs( fc )> 0&&fa*fc < 0 )
{
b = c;
}
}
printf("root is %lf\n",c);
return 0;
}
|
But with the longer code which the root is supposed to be
-2.4334 for (x*x*x)+2(x*x)+x+5 between -4 and 1
it came out wrong
so I think the problem is with rows 1 to 26
which is supposed to scanf with the first input x
being the number of terms (x≤100)
than input the next x numbers which i defined as a[x] in my code being the coefficients
after that input another x numbers which is exponents in each term
which is defined as b[x] here (must>=0)
as for j and k it is just for defining the interval of the root
provided that j<k and f(j)*f(k)<0