Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- double pi(unsigned N)
- {
- double x, y;
- unsigned n = 0;
- for(unsigned i = 0; i < N; ++i)
- {
- x = 1.0 * (rand() - 1) / 32766;
- y = 1.0 * (rand() - 1) / 32766;
- if(x * x + y * y <= 1)
- ++n;
- }
- return 4.0 * n / N;
- }
- int main()
- {
- srand(static_cast<unsigned>(time(nullptr)));
- cout << pi(100000000) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment