The value for can be determined by the series equation Pi= 4 × (1 (1/3) + (1/5)
ID: 1717078 • Letter: T
Question
The value for can be determined by the series equation
Pi= 4 × (1 (1/3) + (1/5) (1/7) + (1/9) -(1/11) + (1/13) - .........)
Write a program in C to approximate the value of using the formula given including
terms up through 1/99.
Create the following table in the format below:
n Pi(estimate) pi(actual)
---- ------------------ ------------
2 2.66667 3.14159
4 2.8952? 3.14159
6 y.yyyyy z.zzzzz
... ... ...
vvv x.xxxxx z.zzzzz
Write a function that estimates pi using an even numbre of terms. The input parameter is the number of terms (an even integer>0). The ouput is an estimate of pi with that many terms.
For example, if n=2, the output would be:
4 * (1-1/3)=2.6667
If n=4, the output woulf be:
4 * (1- 1/3 + 1/5 - 1/7)= 2.8952
Explanation / Answer
#include <stdio.h>
#include<math.h>
void main()
{
public int a,n;
public float actualpivalue = 3.14159;
public float m,o;
m=1-1/3;
float pie;
if (n=2)
{
m=1-1/3;
pie=4*m;
}
for(a=3;a<100;a++)
{
if (n=a-1)
o=(1/(a+2)-1/(a+4));
pie=4*m*o;
a++;
printf(" pi actual=3.1415 ");
printf(" %f pi estimate="+pie);
}
end if;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.