Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Join our Q&A platform and get accurate answers to all your questions from professionals across multiple disciplines. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.
Sagot :
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.
We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. We're glad you visited Westonci.ca. Return anytime for updated answers from our knowledgeable team.