Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

calculate pi with a desired accuracy c++ write a program like the following one.

ID: 3554731 • Letter: C

Question

calculate pi with a desired accuracy c++

write a program like the following one. Thanks

include <iostream>
#include <cmath>
using namespace std;

double deriv(double x);
double fun(double x);

int main()
{
double newx, lastx, diff, acc;
cout << "Enter initial approximation: ";
cin >> lastx;
cout << "Enter accuracy: ";
cin >> acc;

do
{
newx = lastx - fun(lastx)/deriv(lastx);
diff = newx-lastx;
cout << lastx << endl;
lastx = newx;
}
while (abs(diff) > acc);

return 0;
}

double fun(double x)
{
return pow(x, 3) - 3;
}

double deriv(double x)
{
return 3*x*x;;
}

Explanation / Answer

this one is the correct program... glad to help...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote