1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alex777 [14]
3 years ago
13

Write a c++ program to calculate the approximate value of pi using this series. The program takes an input n that determines the

number of values we are going to use in this series. Then output the approximation of the value of pi. The more values in the series, the more accurate the data. Note 5 terms isn’t nearly enough. You will try it with numbers read in from a file. to see the accuracy increase. Use a for loop for the calculation and a while loop that allows the user to repeat this calculation for new values n until the user says they want to end the program.
Create an input file with nano lab04bin.txt


12


123


1234


12345


123456


1234567


12345678


123456789


It has to be written in c++
Computers and Technology
1 answer:
Tanya [424]3 years ago
6 0

Answer:

#include <iostream>

#include <iomanip>

using namespace std;

int main() {

  char choice;

  cout << setprecision(12) << endl;

  while(true) {

      int sign = 1;

      double pi = 0;

      cout << "Enter number of terms: ";

      long n;

      cin >> n;

      for(long i = 1; i < n; i += 2) {

          pi += sign/(double)i;

          sign = -sign;

      }

      pi *= 4;

      cout << "value of pi for n = " << n << " is " << pi << endl;

      cout << "Do you want to try again(y or n)? ";

      cin >> choice;

      if(choice == 'n' || choice == 'N') {

          break;

      }

  }

  return 0;

}

Explanation:

You might be interested in
Write a setInterval() function that increases the count by 1 and displays the new count in counterElement every 400 milliseconds
Liono4ka [1.6K]

Answer:

var count = 0;

var counterElement = document.getElementById("counter");

counterElement.innerHTML = count;

var interval = setInterval(function () {

   count++;

   counterElement.innerHTML = count;

   if (count === 3) {

       clearTimeout(interval);

   }

}, 400);

5 0
3 years ago
Chris needs to take the opposite of a Boolean value. Which operator does so:
alina1380 [7]
B is the best answer
5 0
3 years ago
What is the definition of assiduous?
LuckyWell [14K]

Answer:

showing great care and perseverance.

6 0
3 years ago
Read 2 more answers
Select the three statements that best describe benefits to testing a system.
tester [92]

Answer:

Following are the three statements which best describe  benefits to testing a system.

Explanation:

First

Allows you to correct inaccurate requirements

Second

Allows you to validate characteristics

Third

Allows you to capture the required behavior of the system

7 0
3 years ago
Murray is a database technician. He has created a single enterprise database system. How is this better than multiple databases
EastWind [94]

Answer:

C

Explanation:

data consistency

5 0
4 years ago
Other questions:
  • Can i uninstall adobe lightroom 6 and reinstall
    13·1 answer
  • To create smartart, switch to the insert tab and use a button in the ____ group.
    12·1 answer
  • A toolkit is:
    15·1 answer
  • Which layer of the OSI model is responsible for ensuring flow control so that the destination station does not receive more pack
    7·1 answer
  • When the ____ property of an object is set to False, the object will not appear on the form when the program starts.
    6·1 answer
  • Taking notes on a customer complaint is a form of a communication<br> TRUE OR FLASE
    10·1 answer
  • List at least five smaller behaviours you could break the complex behaviour ""brushing my teeth"" into.
    6·1 answer
  • Given the message size of 16Kb, packet size of 2Kb, speed of 4Kbps over 3 links, how much time, will it take the message to trav
    6·1 answer
  • Name 6 examples of how telemedicine is used in healthcare
    7·1 answer
  • which kind of system software tells the computer how to communicate with peripherals, such as a printer or scanner?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!