aliyahgregory
07.10.2021 •
Computers and Technology
When you leave a slack channel does it delete personal messages
Solved
Show answers
More tips
- C Computers and Internet How to Reinstall Windows: A Detailed Guide for Beginners...
- S Style and Beauty How to Get Rid of a Bruise: Tips and Tricks...
- F Food and Cooking Лечо: вкусное и простое блюдо для любой кухни...
- H Health and Medicine Relieving Swelling in Legs: Causes and Ways to Alleviate the Symptom...
Answers on questions: Computers and Technology
- C Computers and Technology Assume the integer variable num has been assigned a valid value. what is the purpose of the following code segment? if(num % 4 0) system.out.print(num); 1.)it prints num if...
- C Computers and Technology You work in the educational software industry. your boss asks you to give a brief lecture to other employees about the digital divide. create a one-page document in which you...
- C Computers and Technology How do I report admin abuse? I gave an answer but then my answer was deleted with the reason being, This is a great question for a calculator. Other members won t be able to...
- M Mathematics Q11 2 D- 2a u = 26.2 correct to 3 significant figures a = 4.3 correct to 2 significant figures (a) Calculate the upper bound for the value of D. Give your answer correct to...
- M Mathematics 12. Julle is looking through a catalogue for ice-cream. She can buy 2 L of triple-chocolate ice cream for $6.30 while the vanilla fudge ice-cream is usually $5.40 for 1.2 L....
- P Physics Which cartoon character do you think is the smartest?...
- E English Poate cineva sa ma ajute ?...
- B Biology In one area of the Arctic the number of deer has been counted every five years since 1940. The graph shows the number of deer. Suggest a reason why the deer population changed...
- M Mathematics Change 27/4 into a mixed number : Change 3 1/4 into an improper fraction : Show that 1/4+3/5=17/20...
- M Mathematics Please answer my questions...
Ответ:
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.