Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- float prob(int n, int x, float p) {
- if(x == 0) return pow((1-p), n);
- else{
- float result = ((float)p/(1-p)) * ((float)(n-x+1)/(x)) * prob(n, x-1, p);
- cout << "P(X = " << x << ") = " << result << "\n";
- return result;
- }
- }
- int main() {
- int n;
- float p;
- cout << "Enter the number of trials and probability of success respectfully: \n";
- cin >> n >> p;
- prob(n, n, p);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement