(Calculating ?) Calculate the value of ? from the infinite series Print a table that shows the approximate value of ? after each of the first 1000 terms of this series.
What will be an ideal response?
```
// Approximate value for pi.
#include
#include
using namespace std;
int main()
{
long double pi = 0.0; // approximated value for pi
long double denom = 1.0; // denominator of current term
long accuracy = 1000; // number of terms
// set floating-point number format
cout << fixed << setprecision( 8 );
// display table headers
cout << "Accuracy set at: " << accuracy << "\n\nterm\t\tpi\n";
// loop through each term
for ( long loop = 1; loop <= accuracy; loop++ )
{
if ( loop % 2 != 0 ) // if odd-numbered term, add current term
pi += 4.0 / denom;
else // if even-numbered term, subtract current term
pi -= 4.0 / denom;
// display number of terms and
// approximated value for pi with 8 digits of precision
cout << loop << "\t\t" << pi << '\n';
denom += 2.0; // update denominator
} // end for
cout << endl;
} // end main
```
You might also like to view...
What method of the String class would help you check if a string ends with a certain sequence of characters?
What will be an ideal response?
Case-Based Critical Thinking QuestionsCase 10-2Misaki is a new Reservation Specialist for an event rental company. She has asked the database administrator, Kirk, to develop an interface for her to access the database objects she needs because she is not familiar with Access. Kirk agrees to create the interface. He realizes that the greatest benefit of the interface is to minimize ____.
A. the user's ability to use the database B. the information available from the database C. data being corrupted inadvertently D. the administration of the database
In the context of information security, confidentiality is the right of individuals or groups to protect themselves and their information from unauthorized access.
Answer the following statement true (T) or false (F)
As shown in the accompanying figure, a closed envelope icon appears for an unread message.
Answer the following statement true (T) or false (F)