#include #include #include using namespace std; //const unsigned int MAX {numeric_limits::max()}; const unsigned int MAX {1000000000}; //const unsigned int MAX {100000}; int main() { unsigned int trials{0}, hits{0}; float x,y; while (trials < MAX) { x = static_cast(rand()) / RAND_MAX; y = static_cast(rand()) / RAND_MAX; if (x*x+y*y < 1) { hits = hits + 1; } trials = trials + 1; } cout << setw(10) << "Hits " << setw(20) << hits << endl; cout << setw(10) << "Trials " << setw(20) << trials << endl; cout << setprecision(20); cout << "Pi is about " << 4.0 * static_cast (hits) / static_cast(trials) << endl; return 0; }