The value for pi can be determined by the series equation pi

The value for pi can be determined by the series equation: pi = 4 times (1-1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - ...) Write a program that prompts the user to enter the number of iterations title executed to determine the value of v.

Solution

#include<iostream>

int main()
{
   float pi, den=3, iter, val=0;;
   int op=1;
  
   cout <<\"Enter no of iterations \";
   cin >>iter;
   for(int i=0;i<iter;i++)
   {
       if(op==0)
       {
           val=val+1/den;
           op=1;
          
          
       }
       else
       {
           val=val-1/den;
           op=0;
          
       }
      
       den+=2;
   }
  
  
  
   pi=4*(1+val);
  
   cout << \"Value of PI \"<<pi;
}

 The value for pi can be determined by the series equation: pi = 4 times (1-1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - ...) Write a program that prompts the user to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site