Create a function that computes the approximation of pi, based on the number of iterations specified, pi can be computed by 4*(l-l/3+l/5-l/7+l/9-…).
Answers
Answered by
0
Answer:
int calPi(int n)
{
double pi=1;
for(int i=1;i<=n;i++)
{
if(i%2==1){pi=pi-1/(2i+1);}
else{ pi=pi+1/(2i+1);}
}
return pi
}
Explanation:
Answered by
0
The function that calculates the approximation of pi is as follows:
def approx(n): //function
x = 1 // declared variable x
a = 0 // declared variable a
while x<=n: // while loop
a = a + ((4/float( 2* x- l ) n-l )* *( x + l ) ) // formula to calculate pi
i = i + l
return a
Similar questions
English,
5 months ago
Chemistry,
5 months ago
Social Sciences,
5 months ago
Computer Science,
10 months ago
Computer Science,
10 months ago
Physics,
1 year ago