/* Jonathan Hauenstein - University of Notre Dame Center for Applied Mathematics Minicourse on Parallel Computing April 24, May 1, May 8, 2008 Sample programs are designed for educational use */ #include #include int samples_in_circle(int num_samples) { // generates 'num_samples' sample points in [-1,1] x [-1,1] // and returns the number of them that are in the unit circle int i, count = 0; double x, y; // seed the random number generator srand(time(NULL)); for (i = 0; i < num_samples; i++) { // generate x & y in [-1,1] x = 2 * (rand() / (RAND_MAX + 1.0) - 0.5); y = 2 * (rand() / (RAND_MAX + 1.0) - 0.5); // determine if (x,y) is in unit circle if (x*x + y*y <= 1) count++; } return count; }