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