Advertisement
MeehoweCK

Untitled

Nov 10th, 2021
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 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.     unsigned n = 0;
  12.     double x, y;
  13.  
  14.     srand(time(nullptr));
  15.  
  16.     for(unsigned i = 0; i < N; ++i)
  17.     {
  18.         x = 1.0 * rand() / RAND_MAX;
  19.         y = 1.0 * rand() / RAND_MAX;
  20.         if(x * x + y * y <= 1)
  21.             ++n;
  22.     }
  23.  
  24.     cout.precision(10);     // ustala liczbÄ™ wypisywanych cyfr
  25.     cout << "Liczba pi wynosi w przyblizeniu " << 4.0 * n / N << endl;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement