# C++ Program for Secant Method to find the roots of an Equation

```//Secant Method for finding the roots of an equation
#include
#include
#include
using namespace std;
double f(double x);    //declare the function for the given equation
double f(double x)    //define the function here, ie give the equation
{
double a=pow(x,3)-x-11.0;    //write the equation whose roots are to be determined
return a;
}
int main()
{
cout.precision(4);
cout.setf(ios::fixed);        //set the precision of the output
double a,b,c,e;
cout<<"Enter the initial guess\na=";
cin>>b;
cout<<"b=\n";                //take an intial guess
cin>>c;
cout<<"Enter the degree of accuracy\n";
cin>>e;                    //take the desired accuracy
do
{
a=b;
b=c;                //make b equal to the last calculated value of c
c=b-(b-a)/(f(b)-f(a))*f(b);    //calculate c
if (f(c)==0)
{
cout<<"\nThe root of the equation is "<=e);            //check if the error is greater than the desired accuracy
cout<<"\nThe root of the equation is "< Explanation of the code: Manas SharmaPhD researcher at Friedrich-Schiller University Jena, Germany. I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.Share this:Click to share on Facebook (Opens in new window)Click to share on Twitter (Opens in new window)Click to share on Google+ (Opens in new window)Click to share on WhatsApp (Opens in new window)Click to share on Pinterest (Opens in new window)Click to share on Reddit (Opens in new window)Click to share on LinkedIn (Opens in new window)Click to share on Skype (Opens in new window)Click to email this to a friend (Opens in new window)Click to print (Opens in new window)Click to share on Tumblr (Opens in new window)Click to share on Pocket (Opens in new window)Click to share on Telegram (Opens in new window)Like this:Like Loading...

Related

[wpedon id="7041" align="center"]
```

## 4 thoughts on “C++ Program for Secant Method to find the roots of an Equation”

1. how can i get PDF including some of this numerical problem with solution??

2. the code given is differebt from the one used in the video