Advertisement
MeehoweCK

Untitled

Jun 29th, 2021
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. // szacowanie liczby PI
  8.  
  9. const int N = 1000000000;
  10.  
  11. int main()
  12. {
  13.     int n = 0;
  14.     double x, y;
  15.  
  16.     srand(time(nullptr));
  17.  
  18.     for(int i = 0; i < N; ++i)
  19.     {
  20.         x = 1.0 * rand() / RAND_MAX;
  21.         y = 1.0 * rand() / RAND_MAX;
  22.  
  23.         if(x*x + y*y <= 1)
  24.             ++n;
  25.     }
  26.  
  27.     cout << "Liczbe PI oszacowano na " << 4.0 * n / N << endl;
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement