Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- 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);
- printf("P(X = %d) = %.10f\n", x, result);
- return result;
- }
- }
- int main()
- {
- int n;
- float p;
- printf("Enter the number of trials and probability of success respectfully: \n");
- scanf("%d %f", &n, &p);
- printf("The results for different trials are: \n");
- prob(n, n, p);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement