Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void monteCarlo() {
- double przedial = 100000;
- double a = 0;
- double b = 3.14159265359;
- srand((unsigned)time(NULL));
- //std::cout << RAND_MAX;
- double ymax = 1.0;
- double ymin = 0.0;
- double ile=0;
- for (int i = 0; i < przedial; i++) {
- double x= (double)(std::rand()) / (double)RAND_MAX;;
- double y= (double)(std::rand()) / (double)RAND_MAX;
- x *= 3.14159265359;
- //std::cout << x << " " << y << std::endl;
- // system("pause");
- if ((y > 0) && (y < fx(x)))
- ile++;
- }
- double calka =( ile/przedial) * 3.14*1.0 ;
- std::cout << calka<<std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement