Advertisement
TawratNibir

Binomial distribution

Jan 24th, 2025 (edited)
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. float prob(int n, int x, float p) {
  4.     if(x == 0) return pow((1-p), n);
  5.     else{
  6.         float result = ((float)p/(1-p)) * ((float)(n-x+1)/(x)) * prob(n, x-1, p);
  7.         cout << "P(X = " << x << ") = " << result << "\n";
  8.         return result;
  9.        
  10.     }
  11. }
  12. int main() {
  13.     int n;
  14.     float p;
  15.     cout << "Enter the number of trials and probability of success respectfully: \n";
  16.     cin >> n >> p;
  17.  
  18.     prob(n, n, p);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement