/*
 * Monte Carlo calculations of the area between graphs of two functions
 * y = e^x - 1 and y = sin(pi*x/2)
 */

#include <math.h>

#include <gsl/gsl_rng.h>

double area(long m, gsl_rng *r)
{
   double x, y;       /* x,y coordinate, both between 0 and 1  */
   long count = 0L, n;

   for (n = 0; n < m; n++) 
   {
      /* generate random coordinates */
      x = gsl_rng_uniform(r);
      y = gsl_rng_uniform(r);

      /* count when a point lands in the area of interest */
      if ( (y > (exp(x) - 1.)) && (y > sin(M_PI*x/2)) )
      {
         count += 1;
      }
   }

   return(((double)count)/((double)m));

}