Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4. int stp(int a, int b)
  5. {
  6.     int rt=1;
  7.     int i=1;
  8.     while(i<=b)
  9.     {
  10.         i++;
  11.         rt = rt*a;
  12.     }
  13.     return rt;
  14. }
  15.  
  16. int main( )
  17. {
  18. double tmp=0;
  19. int n=0;
  20. int i=0;
  21. double p=0;
  22. cout << "n = ";
  23. cin >> n;
  24. cout << "" << endl;
  25. cout.precision(15);
  26. clock_t stime=clock();
  27.  
  28. while(i<n)
  29. {  
  30.     int tmp2 = stp(-1,i);
  31.     double tmp3 = (double)1/(1+6*i);
  32.     double tmp4 = (double)1/(5+6*i);
  33.     tmp = tmp2*( tmp3 + tmp4 );
  34.     p = p + tmp;
  35.     i++;
  36.     cout << "i = " << i <<"     time = " << (int)(clock()-stime)/CLOCKS_PER_SEC << "     pi = " << p*3 << endl;
  37. }
  38. cin >> n;
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement