The value of π can be determined by the series equation
π=4 ∗ ( 1-1/3 +1/5−1/7+1 / 9−1 / 11+1 / 13 )
Write a program that prompts the user to enter a positive odd number n and uses recursion to approximate the value of π using the given formula including term up through 1/n.
i have did the following.. rectify my mistake.. thanks in advance
kindly help me
π=4 ∗ ( 1-1/3 +1/5−1/7+1 / 9−1 / 11+1 / 13 )
Write a program that prompts the user to enter a positive odd number n and uses recursion to approximate the value of π using the given formula including term up through 1/n.
i have did the following.. rectify my mistake.. thanks in advance
#include <iostream>
using namespace std;
void main()
{
int n;
double f;
double ans =0 ;
cin >> n;
for (int i=0; i<n ; i++)
{
f = 4 * (1/(2*i + 1));
if ((i %2) == 1 )
f = -(f);
else
f=f;
ans += f;
}
}
cout << ans << endl;
}
kindly help me