Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <stdlib.h>
- using namespace std;
- #define pi 3.14159265359
- double AproxPi(unsigned n){
- double piAprox = 0, r;
- srand((time(NULL)));
- while(n){
- r = ((double) rand() / (RAND_MAX));
- if(piAprox + r <= pi)
- piAprox += r;
- n--;
- }
- return piAprox;
- }
- int main ()
- {
- unsigned n;
- cout <<"Numarul de numere generate: "; cin >> n;
- cout <<"Rezultatul aproximari lui pi cu cele " << n << " generate este "<<AproxPi(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement