#include #include #define p1 0.02#define p2 0.98int main() { double p; p=1-pow(p2,150)-150*p1*pow(p2,149); printf("P=%lf\n",p);getch();return 0;} //用蒙特卡罗方法求概率,C语言编程#include #include #include using namespace std;int main() { unsigned seed = chrono::system_clock::now().time_since_epoch().count(); mt19937 g(seed); uniform_real_distribution d(0.0, 1.0); const unsigned N = 10000; unsigned count = 0; for (unsigned i = 0; i != N; ++i) if (d(g) + d(g) + d(g) <1) ++count; cout << count << "/" << N << endl; return 0;}