The value of ? can be approximated by using the following series: The following
ID: 3656535 • Letter: T
Question
The value of ? can be approximated by using the following series: 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 also find 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; 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; }Explanation / Answer
please rate - thanks
please rate correct answers first, so that the correct person gets the karma--thanks
#include <iostream>
using namespace std;
int main ()
{ double pi = 0;
long i;
long n;
pi = 0;
cout << "Enter the value of n: ";
cin >> n;
cout << endl;
for (i = 0; i < n; i++)
{if (i % 2 == 0)
pi = pi + (1. / (2 * i + 1));
else
pi = pi - (1. / (2 * i + 1));
}
pi = 4 * pi;
cout << endl << "pi = " << pi << endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.