Westonci.ca is your trusted source for finding answers to all your questions. Ask, explore, and learn with our expert community. Experience the convenience of finding accurate answers to your questions from knowledgeable professionals on our platform. Explore comprehensive solutions to your questions from a wide range of professionals on our user-friendly 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.
Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. We hope this was helpful. Please come back whenever you need more information or answers to your queries. Westonci.ca is here to provide the answers you seek. Return often for more expert solutions.