Last active
May 4, 2018 22:47
-
-
Save ScratchyCode/d19884b3bef81f74f6e8375417d045e1 to your computer and use it in GitHub Desktop.
The poissonian probability for N events with average A.
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
// Coded by ScratchyCode | |
// Compile in gcc with option -lm | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
double factorial(long long int N); | |
int main(void){ | |
long long int N; | |
double A, P; | |
do{ | |
printf("\nEnter the number of events N: "); | |
scanf("%lld",&N); | |
}while(N < 0); | |
if(N >= 20){ | |
printf("\nNumber too large!\n"); | |
exit(1); | |
} | |
do{ | |
printf("\nEnter the average A for the N events: "); | |
scanf("%lf",&A); | |
}while(A<0); | |
P = (double)(pow(A,N) * exp(-A)) / (double)factorial(N); | |
printf("\nThe poissonian probability for %lld events with average %lf is: %.20lf\n\n",N,A,P); | |
return 0; | |
} | |
double factorial(long long int N){ | |
double i, F=1; | |
if(N==0){ | |
return 1; | |
} | |
for(i=1; i<=N; i++){ | |
F = F * i; | |
} | |
return F; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment