Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- #include <time.h>
- using namespace std;
- double f(double x, double y)
- {
- return x*x+y*y;
- }
- double Monte(double (*Fxy)(double, double),int n)
- {
- double x, y, z;
- double j=0;
- srand(time(0));
- for (int i=0; i<n; i++)
- {
- x=0.5+(rand()%5001)/10000.0;
- y=0.0+(rand()%10001)/10000.0;
- z=0.0+(rand()%10001)/5000.0;
- if ((y<=(2*x-1))&&(z<=Fxy(x,y)))
- {
- j++;
- }
- }
- return j/n;
- }
- int main()
- {
- int n;
- double INT;
- cout<<"Enter number of dots"<<endl;
- cin>>n;
- INT=Monte(f,n);
- cout<<INT<<endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement