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 recursive function that takes an odd number n and uses recursion to
approximate the value of π using the given formula including term up through 1/n.
Your function prototype must be as follows:
float PiValue(int n);
Calling this function “PiValue(1875)” should give the answer 3.14052655581
i am really stuck in this program . Can anyone help me?
#include<cmath>
#include<iostream>
using namespace std;
float pic(int n)
{
float pi=4*(pow(1,n)*(1/(2*n-1)));
if(n==1)
{
return pi;
}
else
{
return pi+pic(n-1);
}
}
int main()
{
int num;
cout<<"Enter the odd number "<<endl;
cin>>num;
int r=pic(num);
cout<<r<<endl;
return 0;
}