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.