Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- int stp(int a, int b)
- {
- int rt=1;
- int i=1;
- while(i<=b)
- {
- i++;
- rt = rt*a;
- }
- return rt;
- }
- int main( )
- {
- double tmp=0;
- int n=0;
- int i=0;
- double p=0;
- cout << "n = ";
- cin >> n;
- cout << "" << endl;
- cout.precision(15);
- clock_t stime=clock();
- while(i<n)
- {
- int tmp2 = stp(-1,i);
- double tmp3 = (double)1/(1+6*i);
- double tmp4 = (double)1/(5+6*i);
- tmp = tmp2*( tmp3 + tmp4 );
- p = p + tmp;
- i++;
- cout << "i = " << i <<" time = " << (int)(clock()-stime)/CLOCKS_PER_SEC << " pi = " << p*3 << endl;
- }
- cin >> n;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement