Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <math.h>
- #include <chrono>
- #include <ctime>
- using namespace std;
- int main()
- {
- int i;
- int j=0;
- int N=1;
- double x;
- double z;
- double err;
- auto start = std::chrono::system_clock::now();
- do
- {
- x=0;
- for(i=1; i<=N; i++) // wartosc PI
- {
- z=pow((i-0.5)/N,2);
- x =x+ 1/(1+z);
- }
- x=4*x/N;
- //cout<<x<<endl;
- err = x-M_PI;
- N=N+10;
- }while(err>=1.5e-6);
- do
- {
- x=0;
- for(i=1; i<=N; i++) // PI value
- {
- z=pow((i-0.5)/N,2);
- x =x+ 1/(1+z);
- }
- x=4*x/N;
- //cout<<x<<endl;
- err = x-M_PI;
- N++;
- }while(err>=1e-6);
- auto end = std::chrono::system_clock::now();
- std::chrono::duration<double> elapsed_seconds = end-start;
- std::time_t end_time = std::chrono::system_clock::to_time_t(end);
- cout<<"Nmin is = "<<N-1<<endl<<"Error for Nmin is = "<<err<<endl<<endl;
- std::cout << "finished computation at " << std::ctime(&end_time)
- << "elapsed time: " << elapsed_seconds.count() << "s\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement