Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BinomialPoisson
//g++ 7.4.0 //calculating probability under Binomial distribution and under Poisson distribution //created by Rezaul Hoque on December 14,2020 //contact at jewelmrh@yahoo.com #include <iostream> #include <cmath> using namespace std; //factorial function float factorial(float); float factorial (float n) { if(n<0) return 0; float f=1; while (n>1) f *= n--; return f; } int main () { float p,bevent,pevent,q, n, x, lam, top; cout<<"Enter number of trials, probability of the event (success) in single trial, number of times the event will occur in the overall trial:\n"; cin>>n>>p>>x; q= 1-p; top=n-x; //probability under binomial distribution bevent=factorial(n)*pow(p,x)*pow(q,top)/(factorial(x)*factorial(top)); lam=n*p; //probability under poisson distribution pevent=pow(lam,x)/(factorial(x)*exp(lam)); cout <<"Probability under binomial distribution: "; cout<<bevent; cout <<endl; cout<<"Probability under Poisson distribution:\n"; cout<<pevent; cout<<endl; return 0; }
run
|
edit
|
history
|
help
0
std::function ambiguity gcc
codechef
Nieparzyste w macierzy
Aplicatie-Proiect
Clementina
SVGAnimated Value
map sort
Count of factors
Boost phoenix. e.g 3 phoenix: functor
Undefined behaviour