Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  asdasda
Language: C/C++
Code:
#include <iostream>
#include <iomanip>
#include <chrono>
#include <thread>

using namespace std;
using namespace std::chrono;

int main() {

    // Starting time for the clock
    auto start = high_resolution_clock::now();

    // Simulate doing work
long double pi = 4.0;
long double tempPi;
for (int i = 1, j = 3; i <= 100000000; i++, j+=2)
{
    tempPi = static_cast<double>(4)/j;
    if (i%2 != 0)
    {
            pi -= tempPi;
    }
    else if (i%2 == 0)
    {
         pi += tempPi;
    }
}        
cout << "Pi has the value of: " << setprecision(16) << fixed << pi << endl;


    // Ending time for the clock
    auto stop = high_resolution_clock::now();

    auto duration = duration_cast<microseconds>(stop - start);
    cout << "Start time: " << duration_cast<microseconds>(start.time_since_epoch()).count() << endl;
    cout << "End time: " << duration_cast<microseconds>(stop.time_since_epoch()).count() << endl;
    cout << "Time taken by insertion sort: " << duration.count() << " microseconds" << endl;
}
Comments: