提交时间:2024-03-09 16:24:27

运行 ID: 136944

# include <bits/stdc++.h> using namespace std ; double a , b , c , d ; long double f ( double x ) { return a * x * x * x + b * x * x + c * x + d ; } int main ( ) { cin >> a >> b >> c >> d ; for ( double i = -100 ; i <= 100 ; i ++ ) { double x1 = i , x2 = i + 1 ; if ( f ( x1 ) == 0 ) { cout << fixed << setprecision ( 2 ) << x1 << ' ' ; } else if ( f ( x1 ) * f ( x2 ) < 0 ) { while ( x2 - x1 >= 0.001 ) { double xx = ( x1 + x2 ) / 2 ; if ( f ( x1 ) * f ( xx ) <= 0 ) { x2 = xx ; } else { x1 = xx ; } } cout << fixed << setprecision ( 2 ) << x1 << ' ' ; } } return 0 ; }