Cubic equation solver [2001 NOIP improve group]

## one dollar cubic equation solving ##

Title Description

Such As: ax3 + bx2 + cx + d = 0 Such a simple cubic equation. The coefficients (a, b, c, d are real numbers) of the equation, and the convention there are three distinct real roots of the equation (root range between -100 and 100), and the roots and roots ≥1 absolute value of the difference.
Requires ascending row are sequentially output in the same three real roots (spaces between root and root), accurate to one decimal place.

Tip: Kee equation f (x) = 0, if present, the number 2 x1 and x2, and x1 <x2, f (x1) * f (x2) <0, then between (x1, x2) there must be a root .

Input
Output
Sample input
1-5-420
sample output
-2.00 2.00 5.00

First saw the title on the scared, the results of it? ? Make violence over water. . . .

#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    double a,b,c,d;
    scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
    for(double x=-100;x<=100;x+=0.01)
    {
        if(abs(a*x*x*x+b*x*x+c*x+d)<=0.00001)printf("%.2f ",x);
    }
    return 0;
} 

Guess you like

Origin www.cnblogs.com/candy067/p/11402005.html