Day 5: Poisson Distribution I | 10 Days Of Statistics | HackerRank Solution

Hello coders, today we are going to solve Day 5: Poisson Distribution I HackerRank Solution which is a Part of 10 Days of Statistics Series.

Day 5: Poisson Distribution I


In this challenge, we learn about Poisson distributions. 


A random variable, X, follows Poisson distribution with mean of 2.5. Find the probability with which the random variable X is equal to 5.

Input Format

The first line contains X‘s mean. The second line contains the value we want the probability for:


If you do not wish to read this information from stdin, you can hard-code it into your program.

Output Format

Print a single line denoting the answer, rounded to a scale of 3 decimal places (i.e., 1.234 format).

Solution – Poisson Distribution I


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int fact(int n)
    if(n < 2)
        return 1;
    return n*fact(n-1); 

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    double prob = ((pow(2.5, 5))*(pow(2.71, (-2.5))))/fact(5);
    printf("%0.3f", prob);
    return 0;

Disclaimer: The above Problem (Poisson Distribution I) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *