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

CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
ReneRene
Change my mind. I dare you.
Chat with Rene
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra

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