MeehoweCK

Untitled

Apr 22nd, 2021
626
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. unsigned long long N = 1000000000;
  8.  
  9. double pi()
  10. {
  11.     double x, y;
  12.     unsigned long long n = 0;
  13.     double postep = 0.1;
  14.  
  15.     srand(time(nullptr));
  16.     cout << "Wykonano 0%\n";
  17.     for(unsigned long long i = 0; i < N; ++i)
  18.     {
  19.         if(1.0 * i / N >= postep)
  20.         {
  21.             system("cls");      // odświeżenie ekranu konsoli
  22.             cout << "Wykonano " << 100.0 * i / N << "%\n";
  23.             postep += 0.1;
  24.         }
  25.         x = 1.0 * rand() / RAND_MAX;
  26.         y = 1.0 * rand() / RAND_MAX;
  27.         if(x*x + y*y <= 1)
  28.             ++n;
  29.     }
  30.     system("cls");
  31.     return 4.0 * n / N;
  32. }
  33.  
  34. int main()
  35. {
  36.     double wynik = pi();
  37.     cout << "Liczbe PI oszacowano na " << wynik << endl;
  38.     return 0;
  39. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×