Write a function using a loop to approximate the value of PI using the formula given including terms up through 1/99, 1/999 and 1/9999. As the number of iterations increase, the estimate gets closer to the value of PI. The function should accept the number of iterations and return the estimate of PI.

Answers

Answer 1

Answer:

Following are the code to the given question:

#include <stdio.h>//header file

double estPi(int precision)//defining a method estPi that accepts value in parameter  

{

   double pi = 0, sign = 1, n = 1;//defining a double variable

   while (n <= precision) //use while loop that checks n value less than equal to precision

   {

       pi += sign / n;//defining pi variable that holds quotient value

       sign *= -1;//holding value in sign value

       n += 2;//increment value in n

   }

   return 4 * pi;//return value

}

int main() //main method

{

   int n;//defining an integer variable

   printf("Enter number of iterations: ");//print message

   scanf("%d", &n);//input value

   printf("Estimated PI is %lf\n", estPi(n));//print method that calls method

   return 0;

}

Output:

Please find the attached file.

Explanation:

In the given code a method "estPi" is declared that holds an integer variable "precision" is declared inside the method multiple double variable is declared inside the loop it calculate the value and return its values.

Inside the main method an integer variable "n" is declared that use print method to input the value and accepting value from the user-end and passing value in the method and print its values.

Write A Function Using A Loop To Approximate The Value Of PI Using The Formula Given Including Terms
Answer 2

Answer:

Following are the code to the given question:

#include <stdio.h>//header file

double estPi(int precision)//defining a method estPi that accepts value in parameter  

{

  double pi = 0, sign = 1, n = 1;//defining a double variable

  while (n <= precision) //use while loop that checks n value less than equal to precision

  {

      pi += sign / n;//defining pi variable that holds quotient value

      sign *= -1;//holding value in sign value

     n += 2;//increment value in n

}

  return 4 * pi;//return value

}

int main() //main method

{

  int n;//defining an integer variable

  printf("Enter number of iterations: ");//print message

  scanf("%d", &n);//input value

  printf("Estimated PI is %lf\n", estPi(n));//print method that calls method

  return 0;

}

Output:

Please find the attached file.

In the given code a method "estPi" is declared that holds an integer variable "precision" is declared inside the method multiple double variable is declared inside the loop it calculate the value and return its values.

Inside the main method an integer variable "n" is declared that use print method to input the value and accepting value from the user-end and passing value in the method and print its values.

Answer: Following are the code to the given question: #include - 1

Explanation:


Related Questions

Find out the actual instruction given in binary

Answers

Your question is incomplete.

hope its helpful.

what is software? what are two types of software?​

Answers

Software is the programs and other operating information used by a computer. Two types of software are system software and Application software. Hope this helps :)

Answer:

Software is the collection of programs which makes computer work. The two types of software are 1)Application software

2)System software

Other Questions
The managers of a brokerage firm are interested in finding out the effects of number of new clients that a broker brings into the firm on the sales generated by them. They sample 10 brokers and identify the number of new clients they have enrolled in the last year and their sales amounts in thousands of dollars. These data are presented in the table that follows: Broker Clients(X) Sales(Y) Calculation shows that 1. 27 52 n=10 2. 11 37 X = 260 3. 40 64 Y= 480 4. 33 55 X2= 7594 5 15 29 Y2= 24276 6. 15 34 XY =13377 7. 25 58 SSX =(X-Xbar)2 =834 8. 36 59 SST=(Y-ybar)2 = 1236 9. 28 44 SSE = (Y Yhat)2=271.241 10. 30 48 (i) Assuming a linear relationship, what is the prediction for the amount for sales (in $1,000s) for a person who brings 25 new clients into the firm? (ii) Calculate the standard error of estimate and interpret the result. (iii) Test at 5% level of significance that the number of new clients that the broker have enrolled in the last year is significant predictor of their sales amount. Completing Form 1040EZDirections - Please complete the Form 1040EZ below based on the following information:Tameka Hunt, 54 Center Street, San Francisco, California 96214-3627Her Social Security number is 999-00-3833. She works as a cashier part-time at PublixSupermarket. She is not claimed on another person's return. According to her W2, she earned$12,675.00 on last year.She is single and claims herself as an exemption. She has $155.00 in Taxable interest she earnedon a Certificate of Deposit. In addition, she had a total of $825.00 withheld in taxes. In addition,Tameka would like her refund to be direct deposited into her personal checking account. Shebanks with First California Bank. The banks routing number is 123321456. Her account numberis 654789987. Based on this information, complete the 1040EZ form for Tameka. (An IRS TaxTable is attached). Prompt: Research one sport played in another country (Cricket, Hurling, Netball, etc.). Describe how the sport is played. Then describe how learning a new sport from another country can help you understand their culture. The graph shows a linear function.10!8642-10-8-6-4-32410-6-104Which table of values has a smaller rate of change than the function in the graph?y-6X-6-7y3456OA..0151216039B.E-6 -8-403-52-481- 20 23114418 A car rental company charges $11 a day and 18 cents per mile to rent their cars. If the total charge for a 2-day rental was $61.60, how many miles were driven? Write and solve and equation. Please, help. Another iReady question. The length of a planet's day is determined by it's why doesnt tsotsi kill the woman and baby in bluegum tree Find the distance x rounded tothe nearest tenth. VilliGroup of answer choicesgenerate movement of materials in the large intestine.are found throughout the gastrointestinal tract.contain both smooth and skeletal muscle fibers.increase surface area in the small intestine.All of the choices are correct Why x rays have different properties from light even though both originate from orbital transition of electrons in excited atoms? What is gravitational force? -,- what is the pH of a 2.58 x 10^-6 M solution of an acid? A triangle has side lengths of [tex] \sqrt{125} [/tex][tex] \sqrt{5} [/tex][tex] \sqrt{20} [/tex] What is the perimeter of the triangle? [tex]4 \sqrt{5} [/tex][tex]6 \sqrt{5} [/tex][tex]8 \sqrt{5} [/tex]none of the answers are correct A right triangle is shown below. What is the length of the side X, to the nearest tenth of a centimeter? The base of a prism is a square 7 cm on a side. The height of the prism is 10 cm. The volume is _?_ cm3. What should I order from McDonald's? best order gets brainliest Which characteristic is associated with winter as compared to summer?Choose the correct answer.noon sun lower in the skyhigher daytime temperaturesmore daily hours of sunlightlonger days and shorter nights Seeking help to solve the problem shown in the image. What is the simplified form of the rational expression below?3^2 - 48/2^2 + 8x