answersLogoWhite

0

#include<iostream>

#include<cmath>

#include<fstream>

using namespace std;

double f(double x);

int main()

{

double dX0, dX1, dX2, dInterations = 0, dTolerance;

cout << "What is the first root guess? ";

cin >> dX0;

cout << "What is the second root guess";

cin >> dX1;

do {

dX2 = dX1 - ((f(dX1) * (dX1 -dX0)) / (f(dX1) - f(dX0)));

dX0 = dX1;

dX1 = dX2;

dTolerance = fabs(dX2 - dX1);

dInterations++;

}

while (dInterations <= 100 dTolerance >= .000001);

cout << "One of the roots is " << dX2 << endl;

}

double f(double x)

{

double dReturn;

dReturn = (3 * x * x) + (2 * x) -2;

return dReturn;

}

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

BeauBeau
You're doing better than you think!
Chat with Beau
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
JudyJudy
Simplicity is my specialty.
Chat with Judy

Add your answer:

Earn +20 pts
Q: How can we write program in c on secant method explain with example?
Write your answer...
Submit
Still have questions?
magnify glass
imp