Advertisement
MeehoweCK

Untitled

Jan 28th, 2021
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. const unsigned N = 1000000000;
  8.  
  9. int main()
  10. {
  11.     srand(time(nullptr));
  12.     double x,y;
  13.     unsigned n = 0;
  14.     for(unsigned i = 0; i < N; ++i)
  15.     {
  16.         x = 1.0 * (rand() - 1) / (RAND_MAX - 1);
  17.         y = 1.0 * (rand() - 1) / (RAND_MAX - 1);
  18.         if(x * x + y * y <= 1)
  19.             ++n;
  20.     }
  21.     cout << "Liczba pi wynosi w przyblizeniu " << 4.0 * n / N << endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement