Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- double calculoPi()
- {
- double vrPi = 0.0;
- int i= 2;
- while (abs(vrPi * 4 -3.1416) > 0.00001)
- {
- double aux1 = ((2.0*i)-2)/(2.0 * i - 1.0);
- double aux2 = ((2.0*i))/(2.0 * i - 1.0);
- vrPi += aux1 * aux2;
- if(aux1 != aux2){
- return vrPi;
- }
- i++;
- }
- return vrPi * 4;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- cout <<"Valor de PI calculado: " << calculoPi() <<endl;
- system ("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment