#include #include #include #include using namespace std; double function(double x) { return log(x)/x; //the function whose area we want to find from x = lower_x to x = upper_x } void montecarlo1(){ int tcount = 0; int in_area = 0; int loopsize, lower_x, upper_x; double x_coord; double y_coord; cout<<"Enter lower x and upper x: "; cin>>lower_x>>upper_x; cout<<"Enter the number of times you want to loop: "; cin>>loopsize; //This part is for generating random number random_device rd; // obtain a random number from hardware mt19937 eng(rd()); // seed the generator uniform_real_distribution<> distribution_x(lower_x,upper_x); // define the range for x uniform_real_distribution<> distribution_y(0, 1/exp(1)); // define the range for y. Note that 1/exp(1) is the maximum y value attained by the function //Done with random numbers part while (tcount < loopsize){ x_coord = distribution_x(eng); //gives random number from 1-10 y_coord = distribution_y(eng); //gives random number from 0 to 1/e if (y_coord < function(x_coord)){ //function(x_coord) gives the functional value. if that functional value is greater than y_coord, we have a point inside the graph in_area += 1; } tcount += 1; } double area_box = (upper_x-lower_x)/exp(1); double area_graph = (in_area*area_box)/tcount; cout<