SHARE
TWEET

Untitled

Alx09 Jun 22nd, 2020 1,121 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. #define pi 3.14159265359
  7.  
  8. double AproxPi(unsigned n){
  9.     double piAprox = 0, r;
  10.  
  11.     srand((time(NULL)));
  12.     while(n){
  13.         r = ((double) rand() / (RAND_MAX));
  14.         if(piAprox + r <= pi)
  15.             piAprox += r;
  16.         n--;
  17.     }
  18. return piAprox;
  19. }
  20.  
  21.  
  22. int main ()
  23. {
  24.     unsigned n;
  25.     cout <<"Numarul de numere generate: "; cin >> n;
  26.     cout <<"Rezultatul aproximari lui pi cu cele " << n << " generate este "<<AproxPi(n);
  27.  
  28. return 0;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top