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
The term eof represents
rewona [7]

Answer:

EOF stands for End Of File

Google explains it well: EOF is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.

8 0
2 years ago
Read 2 more answers
To test for the current date in a query, type ____ in the criteria row of the appropriate column.
lyudmila [28]

Answer:

zxc

Explanation:

zc

6 0
3 years ago
Which of the following statements best describes IT careers?
DiKsa [7]

The answer is (C) IT careers are found in a wide variety of industries.

Nowadays, all types of industries in various different parts of the world will have an IT (information technology) department because it is needed, since most businesses operate using some form of IT equipment, which, most commonly found is a computer. It is a particularly lucrative field because of the wide array of job availability.

7 0
3 years ago
This is the recorded history of the development of a group functioning within an organization. Identify the sentence that refers
Vikentia [17]
This is the recorded history of the development of a group functioning within an organization. Identify the sentence that refers to the norming stage of group development.

. The group then created a working structure that everyone agreed with.

5 0
3 years ago
Read 2 more answers
To close a tab, click the ____ button in the web page thumbnail on the tab switcher.
slavikrds [6]
Tabs are rectangular boxes found on top of your we browser. At the right of each of those tabs, you see a symbol written in 'x' (as shown in the picture). This is the one you should click to close an existing tab.

3 0
2 years ago
Other questions:
  • He would like to get rid of the graph. What will accomplish
    8·1 answer
  • Please look at picture
    10·2 answers
  • In which of the following situations may you pass on the right
    13·2 answers
  • Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively, what is the output of the following code snippet?
    15·1 answer
  • Which feature of a blog allows an author to interact and get feedback from his or her readers? link pingback commenting TweetMem
    9·1 answer
  • Write a c program to count the total number of commented characters and words in a c file taking both types of c file comments (
    11·2 answers
  • What will be the results of the following code? final int Array_Size = 5;An error will occur when the program runs. There will b
    10·1 answer
  • How we can earn from an app​
    12·1 answer
  • Jimmy has been issued a citation for littering in a city park. When Jimmy
    8·1 answer
  • Does my computer have virus?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!