π=4(1-(1/3)+(1/5)-(1/7)+...+(1/(2n-1))+(1/(2n+1))) The following program uses this series to find the approximate value of π. However, the statements are in the incorrect order, and there is also a bug in this program. Rearrange the statements and remove the bug so that this program can be used to approximate π. #include #include using namespace std; int main() { double pi = 0; long i;
The value of π can be approximated by using the following series:
π=4(1-(1/3)+(1/5)-(1/7)+...+(1/(2n-1))+(1/(2n+1)))
The following program uses this series to find the approximate value of π. However, the statements are in the incorrect order, and there is also a bug in this program. Rearrange the statements and remove the bug so that this program can be used to approximate π.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double pi = 0;
long i;
long n;
cin >> n;
cout << "Enter the value of n: ";
cout << endl;
if (i % 2 == 0)
pi = pi + (1 / (2 * i + 1));
else
pi = pi - (1 / (2 * i + 1));
for (i = 0; i < n; i++)
{
pi = 0;
pi = 4 * pi;
}
cout << endl << "pi = " << pi << endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images