[ create a new paste ] login | about

Link: http://codepad.org/baYUk6pM    [ raw code | output | fork ]

C++, pasted on Oct 22:
#include<stdio.h>  
#include<math.h>  
int main()
{  
    double x1,x2,x,y1,y2,y;
    x1=10;
    x2=-10;
    y1=2*x1*x1*x1-4*x1*x1+3*x1-6;
    y2=2*x2*x2*x2-4*x2*x2+3*x2-6;
    do
    {
        x=(x1+x2)*0.5;
        y=2*x*x*x-4*x*x+3*x-6;
        if(y>=0)
            x1=x;
        if(y<0)
            x2=x;
    }
    while(fabs(x1-x2)>=0.0001);
    printf("%f",x2);
    return 0;
}


Output:
1
1.999969


Create a new paste based on this one


Comments: