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