# include float fran ( float a, float b, int *seed ); int main ( ) { int hits; int i; int n = 100; int seed = 123; // // #1: what more declarations must we add here? // hits = 0; for ( i = 0; i < n; i++ ) { x = fran ( -1.0, +1.0, &seed ); y = fran ( -1.0, +1.0, &seed ); // // #2: Fill in the "condition" in the following IF statement: // // An IF statement has the form // // if ( condition ) // // You need to write an arithmetic statement about x and y that is // true if the point (x,y) is inside a circle of radius 1. // If you have trouble with this, please ask Detelina for advice! // if ( (x,y) is inside the circle ) { hits = hits + 1; } } // // #3: Compute the estimate, the exact area, and the error. // area_estimate = number of hits divided by total number of tries area_exact = formula for the area of a circle of radius 1 error = | estimate - exact | <-- how do we take the absolute value? // // #4: Print your result. // print n, estimate, exact, and error here. return 0; } float fran ( float a, float b, int *seed ) // // Purpose: // // FRAN returns a scaled pseudorandom float between A and B. // // Parameters: // // Input, float A, B, the limits of the interval. // // Input/output, int *SEED, the "seed" value, which should NOT be 0. // On output, SEED has been updated. // // Output, float FRAN, a number between A and B. // { int i4_huge = 2147483647; int k; float value; // // Check SEED. // if ( *seed == 0 ) { printf ( "\n" ); printf ( "FRAN - Fatal error!\n" ); printf ( " Input value of SEED = 0.\n" ); exit ( 1 ); } // // Update SEED. // k = *seed / 127773; *seed = 16807 * ( *seed - k * 127773 ) - k * 2836; if ( *seed < 0 ) { *seed = *seed + i4_huge; } // // Convert SEED to a real number in [0,1]. // value = ( float ) ( *seed ) * 4.656612875E-10; // // Scale to a real number in [A,B]. // value = a + ( b - a ) * value; return value; }