Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- double liczba_pi(unsigned long long N)
- {
- double x, y;
- unsigned long long n = 0;
- srand(time(nullptr));
- for(unsigned long long i = 0; i < N; ++i)
- {
- // losujemy punkt:
- x = (rand() - 1) / 32766.0;
- y = (rand() - 1) / 32766.0;
- // sprawdzamy czy wylosowany punkt zawiera się w ćwierćkole:
- if(x * x + y * y <= 1)
- ++n;
- }
- // zwracamy wynik:
- return 4.0 * n / N;
- }
- int main()
- {
- cout << "Liczbe PI oszacowano na " << liczba_pi(10000000000) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement