#include <iostream>
#include "genlib.h"
#include "random.h"
using namespace std;
int main()
{
cout << "This program averages a series of random numbers\n"
<< "between 0 and 1." << endl;
cout << "How many trials: ";
int n;
cin >> n;
double sum = 0.0;
for (int i = 0; i < n; ++i) {
sum += RandomReal(0.0, 1.0);
}
cout << "The average value after " << n << " trials is "
<< sum / n << endl;
return 0;
}
stanford cs106b random.h demo
最新推荐文章于 2017-07-25 14:53:49 发布