首页 > 代码库 > NOIP200105一元三次方程求解(C++)

NOIP200105一元三次方程求解(C++)

#include<stdio.h>
double a, b, c, d;
double abs (double n) {return (n > 0) ? n : - n;}
double f(double x) {return (((a*x)+b)*x+c)*x+d;}
int main()
{
int k = 0;
scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
for (double i = -10000; i < 10001; i++)
{
if (abs(f(i/100)) < 1e-8)
{
k++; printf("%.2lf", double(i/100));
if (k < 3) printf(" ");
else printf("\n");
i += 10;
}
}
}

NOIP200105一元三次方程求解(C++)