Last active
November 16, 2018 05:18
-
-
Save 314pies/ade7145095ff712cf456a82cc404ef4b to your computer and use it in GitHub Desktop.
Binomial distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Input: x,n,p (Each inputs should separated by space or line) | |
Output: b(x,n,p) | |
*/ | |
#include<iostream> | |
#include<cmath> | |
using namespace std; | |
long long int factorial(int n){ | |
long long int _result=1; | |
for(int _n = n;n>=1;n--){ | |
_result = _result*n; | |
} | |
return _result; | |
} | |
long long int combination(int n,int x){ | |
return factorial(n)/(factorial(x)*factorial(n-x)); | |
} | |
int main(){ | |
int x,n; | |
double p; | |
while(cin>>x>>n>>p){ | |
cout<<combination(n,x)*pow(p,x)*pow(1-p,n-x)<<endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment