Develop a program to find the roots of the quadratic equation using BISECTION METHOD.
#include<iostream>
using namespace std;
#define EPSILON 0.01
double function(double y)
{
return y*y*y - y*y + 2;
}
void bisectionMethod(double x, double y)
{
if (function(x) * function(y) >= 0)
{
cout << "x and y are not right\n";
return;
}
double root = x;
while ((y-x) >= EPSILON)
{
root = (x+y)/2;
if (function(root) == 0.0)
break;
else if (function(root)*function(x) < 0)
y = root;
else
x = root;
}
cout << "The root value is: " << root;
}
int main()
{
double x =-100, y = 600;
bisectionMethod(x, y);
return 0;
}
Comments
Leave a comment