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
aleksley [76]
3 years ago
13

You've been hired by Fruity Fillers to write a C++ console application that approximates PI. Use a validation loop to prompt for

and get from the user the number of terms to approximate PI to that is between 1 and 10,000. Use the following Leibniz formula:
Computers and Technology
1 answer:
Igoryamba3 years ago
6 0

Answer:

The program to this question can be described as follows:

Program:

#include<iostream> //defining header file

#include<iomanip>

using namespace std;  

int main()  //defining main method

{

int n,i,div = 1;  //defining integer variable

double PI = 0; //defining double variable

cout<< "Enter number of terms: "; //print message

cin >>n;//input number

while(n<1)//loop for input validation

{

cout << "Enter valid number of terms(atleast 1): "; //print message

cin >> n; //input value

}

for(i = 1; i <= n; i++) //loop to calcluate value

{

if(i % 2 == 0)//to check even number

PI =PI- (1.0/(div)); //hold value in PI

else//Odd iteration

PI =PI+ (1.0/(div)); //hold value in PI

div =div+ 2; //increment the value

}

PI =PI* 4;//Multiply summed values by 4

cout << "Approximation of PI = " << setprecision(10) << fixed << showpoint << PI; //print the value

return 0;

}

Output:

Enter number of terms: 8

Approximation of PI = 3.0170718171

Explanation:

In the above program code three integer variable "i,n and div", in which variable div assign a value that is 1, and a double variable PI is defined, that assign a value that is 0.

  • The variable n is used to take input from the user end, that first checks input validation by using a while loop, and then the for loop is declared.
  • Inside the for loop, it will use if statement, that checks even or odd number, in the even number it decrements the value PI, and in the odd number, it will calculate the total PI.  
You might be interested in
A power supply unit for a computer converts:
Vinvika [58]
A power supply unit (or PSU) converts mains AC to low-voltage regulated DCpower for the internal components of acomputer. ... Some power supplies have a manual switch for selecting input voltage, while others automatically adapt to the mains voltage.
5 0
3 years ago
The ........ tag is used to create a link to another document​
Free_Kalibri [48]

Answer:

The "a" tag or <a></a> and its "h<u>r</u>ef" attribute <a href="#"></a>

Explanation:

In html there is only one way to create a link to an external source or a bookmark. The tag is created using the element <a>.

The attribute "href" is then added to describe the link of where it is to point to.

Example:

<a href="google.com">Go to Google</a>

While the text in between the tag describes what the link is about.

7 0
3 years ago
The letters a, e, i, o and u are the only vowels. Write a function named vowelUseDict() takes a string t as a parameter and comp
Andru [333]

Please specify the programming language.


3 0
4 years ago
Individuals and IT professionals have a responsibility to be aware of security threats and the damage they might do.
Veseljchak [2.6K]
The answer is true they will have to be responsible
6 0
3 years ago
Write a program that asks the user for the name of a text file. the program should display the last 10 lines of the file on the
Tom [10]
The only thing that I know is that after you input the text file, it could either:
-save those lines as a variable
-display the text file
However any more would be dependent on the language.
3 0
3 years ago
Other questions:
  • Define a function CoordTransform() that transforms the function's first two input parameters xVal and yVal into two output param
    11·1 answer
  • The PATH environment variable.
    5·1 answer
  • Instructions
    12·1 answer
  • 6. A distribution consists of three components with frequencies 200, 250 and 300 having means
    14·1 answer
  • What is the basic difference between a printer and a plotter?​
    12·1 answer
  • How do optical discs store data? select one:
    15·1 answer
  • Options to open,save,and print a document are found on which of the following tabs? A.File B.Home C. Design D. Layout
    5·2 answers
  • What is a header row?
    8·1 answer
  • What is Data rate?<br> What is BAUD RATE?<br> What is bandwidth?
    8·1 answer
  • Can you explain the difference between software and hardware? Tell me 3 examples of each one.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!