ax2+bx+c=0与x轴围成的面积,怎么用C++编写?要求由流程图,谢谢!
请高手指教!
#include <iostream>
#include <cmath>
using namespace std;
#define ERROR 0
#define OK 1
int solve(double a,double b,double c,double &x1,double &x2)
{
double delta=b*b-4*a*c;
if(delta<0)return ERROR;
x1=(-b-sqrt(delta))/(2*a);
x2=(-b+sqrt(delta))/(2*a);
return OK;
}
double area(double a,double b,double c,double x1,double x2)
{
return fabs(a/3*(x2*x2*x2-x1*x1*x1)+b/2*(x2*x2-x1*x1)+c*(x2-x1));
}
int main()
{
double a,b,c,x1,x2;
scanf(\"%lf %lf %lf\",&a,&b,&c);
if(solve(a,b,c,x1,x2)==OK)
printf(\"%lf\n\",area(a,b,c,x1,x2));
else {
printf(\"0\n\");
}
}