Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2011
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <time.h>
  5. using namespace std;
  6. double f(double x, double y)
  7. {
  8.     return x*x+y*y;
  9. }
  10. double Monte(double (*Fxy)(double, double),int n)
  11. {
  12.     double x, y, z;
  13.     double j=0;
  14.     srand(time(0));
  15.     for (int i=0; i<n; i++)
  16.     {
  17.         x=0.5+(rand()%5001)/10000.0;
  18.         y=0.0+(rand()%10001)/10000.0;
  19.         z=0.0+(rand()%10001)/5000.0;
  20.         if ((y<=(2*x-1))&&(z<=Fxy(x,y)))
  21.         {
  22.             j++;
  23.         }
  24.     }
  25.     return j/n;
  26. }
  27. int main()
  28. {
  29.     int n;
  30.     double INT;
  31.     cout<<"Enter number of dots"<<endl;
  32.     cin>>n;
  33.     INT=Monte(f,n);
  34.     cout<<INT<<endl;
  35.     system("pause");
  36.     return 0;
  37. }
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement