Advertisement
TawratNibir

BinomialC

Jan 28th, 2025
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. float prob(int n, int x, float p)
  5. {
  6.     if (x == 0)
  7.         return pow((1 - p), n);
  8.     else
  9.     {
  10.         float result = ((float)p / (1 - p)) * ((float)(n - x + 1) / (x)) * prob(n, x - 1, p);
  11.         printf("P(X = %d) = %.10f\n", x, result);
  12.         return result;
  13.     }
  14. }
  15.  
  16. int main()
  17. {
  18.     int n;
  19.     float p;
  20.     printf("Enter the number of trials and probability of success respectfully: \n");
  21.     scanf("%d %f", &n, &p);
  22.     printf("The results for different trials are: \n");
  23.     prob(n, n, p);
  24. }
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement