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...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.