int main() { unsigned seed = time(0); srand(seed); bool tag; int T; int x; double res = 0; int n; double a = 0; cout << "请输入循环次数:" << endl; cin >> n; for (int i = 0; i < n; i++) { tag = false; T = 0; for (int i = 0; i < 2; i++) { x = rand() % 2; if (x == 0) { tag = true; T++; } } if (tag) a++; if (tag == true) { if (T == 2) res++; } } double r = res / a; cout << "几率为" << r << endl; }