#include #include // For time() #include // For rand(), srand(), RAND_MAX using namespace std; double my_rand( double a = 0.0, double b = 1.0 ); int main() { srand( time(0) ); // or time(NULL) const int n = 1000; int k; double x[n]; // If using a variable to define the array dimension, make it a const for ( k = 0; k < n; k++ ) { x[k] = my_rand(); } double sum = 0.0; for ( k = 0; k < n; k++ ) { sum += x[k]; } cout << "The average value is " << sum / n << endl; cout << "\n\n"; system( "PAUSE" ); return( 0 ); } double my_rand( double a, double b ) { double x = double ( rand() ) / RAND_MAX; return( a + ( b - a ) * x ); }