Write a C++ program using a while loon for Programming Exercise 5.27 on p. 198 w
ID: 3670743 • Letter: W
Question
Write a C++ program using a while loon for Programming Exercise 5.27 on p. 198 with the following change: Instead of displaying n for values of i shown, use a while loop to continue adding terms until it is accurate to 6 digits after the decimal point. pi = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 +..)Display the following and turn in printouts of the program and the results. The number of terms needed to find n The value of it using acos(-1) using 10 digits alter the decimal point. The value of pi/2 found with the series using 10 digits alter the decimal point (the first 6 digits after the decimal point should match the value above).Explanation / Answer
hI, I have coded the main functionality for this question. Just add extra functionality according to your need.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main (){
double signo=1,denominador=1,serie=0;
int n=0;
while(true) {
serie+=signo/denominador;
signo*=-1;
denominador+=2;
n++;
if(abs(4*serie-3.141592)<= 1e-6) break;
}
cout << fixed << setprecision(6)<<"Iteraciones="<<n<<" Resultado="<<(4*serie)<<endl;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.