binomial distribution

#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <iomanip> using namespace std; double factorial(double n) { if (n) { return n*factorial(n - 1); } else { return 1; } } double nchoosek(double n, double k) { return factorial(n) / factorial(n - k) / factorial(k); } double binom(double k, double n, double p) { return nchoosek(n, k)*pow(p, k)*pow(1 - p, n - k); } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ double a, b; double n,k; cin >> a >> b; cin >> n >> k; double p = a / (a + b); //cout << fixed << setprecision(3) << binom(3, 6, p) + binom(4, 6, p) + binom(5, 6, p) + binom(6, 6, p); cout << binom(k,n,p); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.