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
All of the following can be caused by the movement of geologic plates EXCEPT
Aleks04 [339]
I think storm surges cause fro means world "earth" so a storm surge is like a flood SO plates would cause earth quakes and stuff
8 0
3 years ago
Write a program for determining if a year is a leap year. In the Gregorian calendar system you can check if it is a leaper if it
SOVA2 [1]

Answer:

def leap_year_check(year):

return if int(year) % 4 == 0 and (int(year) % 100 != 0 or int(year) % 400 == 0)

Explanation:

The function is named leap_year_check and takes in an argument which is the year which we wish to determine if it's a new year or not.

int ensures the argument is read as an integer and not a float.

The % obtains the value of the remainder after a division exercise. A remainder of 0 means number is divisible by the quotient and a remainder other wise means it is not divisible by the quotient.

If the conditions is met, that is, (the first condition is true and either the second or Third condition is true)

the function leap_year_check returns a boolean ; true and false if otherwise.

8 0
2 years ago
Which character formatting effect makes text appear in a small font size below the midpoint of a line of text
pav-90 [236]

Answer:

Superscript or Subscript

Explanation:

The superscript or the subscript is a type of character which is set a little lower or more than the normal line of type. And it is generally small as compared to the other texts. The subscript does appear at or less than the baseline, and the superscript is above. And for the superscript, you need to press the Ctrl + Shift + + ( press and at the same time also hold the Ctrl and the Shift, and finally press the +). And for the subscript, you need to press the Ctrl + Shift ++(Press and at the same time also hold the Ctrl. and finally press the =). And pressing the corresponding shortcut once again, you will be back to the normal text.

4 0
3 years ago
Write a function: function solution(N); that, given a positive integer N, prints the consecutive numbers from 1 to N, each on a
koban [17]

Answer:

<em>The program written in Python is as follows:</em>

def solution(N):

     concat = ""

     for i in range(1,N+1):

           if not(i%2 == 0 or i%3 ==0 or i%5 == 0):

                 print(str(i))

           else:

                 if i%2 == 0:

                       concat= concat+"Codility"

                 if i%3 == 0:

                       concat= concat+"Testers"

                 if i%5 == 0:

                       concat= concat+"Coders"

                 print(concat)

                 concat = ""

N = int(input("Enter a positive integer: "))

solution(N)

Explanation:

This line declares the function

def solution(N):

This line initializes a variable named concat to an empty string

     concat = ""

This line iterates from 1 to the input integer

     for i in range(1,N+1):

<em>This line checks if the current number of iteration is divisible by 2,3 or 5, if no, the number is printed</em>

           if not(i%2 == 0 or i%3 ==0 or i%5 == 0):

                 print(str(i))

<em>If otherwise</em>

           else:

<em>This lines checks if current number is divisible by 2; if yes the string "Codility" is concatenated to string concat</em>

                 if i%2 == 0:

                       concat= concat+"Codility"

<em>This lines checks if current number is divisible by 3; if yes the string "Testers" is concatenated to string concat</em>

<em>                 </em> if i%3 == 0:

                       concat= concat+"Testers"

<em>This lines checks if current number is divisible by 2; if yes the string "Coders" is concatenated to string concat</em>

                 if i%5 == 0:

                       concat= concat+"Coders"

<em>The concatenated string is printed using this line</em>

                 print(concat)

This variable concat is intialized back to an empty string

                 concat = ""

The main method starts here

N = int(input("Enter a positive integer: "))

This line calls the defined function solution

solution(N)

6 0
3 years ago
thick is incorrect does anybody know the correct answer? please don’t send any files i can’t open them
77julia77 [94]

Answer:

i think its new

Explanation:

if this is incorrect i apologize

7 0
3 years ago
Other questions:
  • Ten 9600-bps lines are to be multiplexed using TDM. a. Ignoring overhead bits in the TDM frame, what is the total capacity requi
    6·1 answer
  • Double clicking a word selects the entire word?
    9·2 answers
  • The ______ is the information center that drivers need to refer to when they're NOT scanning the road.
    13·1 answer
  • The unique physical address burned into every network interface card is its:
    15·1 answer
  • Which of the following is the SECOND step of the intuitive​ lowest-cost method​?
    12·1 answer
  • What is the maximum current that should be allowed in a 5.0w 220 resistor?
    12·1 answer
  • Write a C program to calculate and display the coordinates of midpoint - M of a linesegment between two given points - say A and
    7·1 answer
  • Credence is a student in college.
    13·2 answers
  • Write a program. Commence the change to be dispensed from a vending machine. An item machine can cost between $0.25 send a dolla
    9·1 answer
  • Write a program that creates a two-dimensional array named height and stores the following data:
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!