#include #include #include double PI=3.14159; double fun(double); double integrate(double, double); main(){ double yy; cout.setf(ios::fixed); cout.precision(4); for(double x = 0.00; x < 1.00; x+=0.10) { yy = integrate(0,x); for(double y = 0.00; y <= yy; y +=0.002) cout << 1 << endl; //<< "\t" << y << "\t "<< 1 << endl; } } /* The following function calculates the area under a function fun. The area is calculated between a and b. The method used to calculate the integral is called the Composite Simpson Rule. */ double integrate(double a,double b) { double steps = 10000; double m = (b-a)*steps; double even = 0, odd = 0; double h = (b-a)/(2*m); double x; for(int k = 1; k < m; k++) { x = a+h*2*k; even += fun(x); } for(int k = 1; k < m+1; k++) { x = a+h*(2*k-1); odd += fun(x); } return h*(fun(a) + fun(b) + 2*even + 4*odd)/3; } /* The following code defines the function over which we intergrate; here it is the density function for the standard normal distribution. */ double fun(double x) { return exp(-(x*x)/2)/sqrt(2*PI); }