+92 332 4229 857 99ProjectIdeas@Gmail.com

Series to calculate value of pie (C++)


Series to calculate value of pie
π (sometimes written pi) is a mathematical constant whose value is the ratio of any circle's circumference to its diameter in the Euclidean plane; this is the same value as the ratio of a circle's area to the square of its radius. It is approximately equal to 3.14159265 in decimal notation.
calculatePIE() returns the accurate value of pie upto 4 decimal places.

Code

#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "iomanip"
#include "math.h"

using namespace std;

double calculatePIE()
{
 int x=1;
 double PIE=4;
  for(double i=3;i<100000;i+=2)
  {
            PIE=PIE+(pow(-1.0,x)*(4/i));
    x++;
  }
return PIE;
}

int main()
{
       cout<<calculatePIE();cout<<endl;

       _getche();
       return 0;
}

Output
3.14157

0 comments: