Jtabord4

Punto 7

Feb 9th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6. double calculoPi()
  7. {
  8.     double  vrPi = 0.0;
  9.     int i= 2;
  10.  
  11.     while (abs(vrPi * 4 -3.1416) > 0.00001)
  12.     {
  13.         double aux1 =  ((2.0*i)-2)/(2.0 * i - 1.0);
  14.         double aux2 =  ((2.0*i))/(2.0 * i - 1.0);
  15.         vrPi += aux1 * aux2;
  16.         if(aux1 != aux2){
  17.         return vrPi;
  18.         }
  19.         i++;
  20.     }
  21.    
  22.     return vrPi * 4;
  23. }
  24.  
  25.  
  26. int _tmain(int argc, _TCHAR* argv[])
  27. {
  28.     cout <<"Valor de PI calculado: " << calculoPi() <<endl;  
  29.     system ("Pause");
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment