Answer to Question #239471 in C++ for rafly

Question #239471

Develop a program and algorithm to find the roots of the quadratic equation using bisection method.


1
Expert's answer
2021-09-20T05:48:37-0400
#include<bits/stdc++.h>
using namespace std;
#define EP 0.01
double function(double m)
{
    return m*m*m - m*m + 2;
}
 
void bisect(double x, double y)
{
    if (function(x) * function(y) >= 0)
    {
        cout << "Assumptions for values of x and y not correct\n";
        return;
    }
 
    double c = x;
    while ((y-x) >= EP)
    {
        c = (x+y)/2;
        if (function(c) == 0.0)
            break;
 
        else if (function(c)*function(x) < 0)
            y = c;
        else
            x = c;
    }
    cout << "The value of root is : " << c;
}
 
int main()
{
	double x,y;
	cout<<"Enter the values of x and y:  "<<endl;
	cin>>x>>y;
    bisect(x, y);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS