问题:
解答:
#include <iostream>
using namespace std;
long double probability(double num1, double num2, double picks)
{
long double result = 1.0;
for (int i = num1;picks>0; i--,picks--)
{
result = result * (picks / i);
}
result *= 1 / num2;
return result;
}
int main()
{
int num1 = 0;
int num2 = 0;
int count;
cout << "请输入普通号码域:";
cin >> num1;
cout << "请输入特殊号码域:";
cin >> num2;
cout << "请输入普通号码中奖的号数:";
cin >> count;
cout << "中头奖的概率为:" << probability(num1, num2, count)<<endl;
return 0;
}
运行结果:
考查点:
- 函数
- 排列组合
2024年8月30日20:11:46