Poisson Distribution in C++

#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; } } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ double lambda, k; cin >> lambda >> k; cout << fixed << setprecision(3) << pow(lambda, k)*exp(-lambda) / factorial(k) << endl; return 0; }

2 Responses

Nice, but why do you need to include <cstdio>, <vector>, and <algorithm> ?
good to see some C++ on here ! keep up the good work !!
Thanks Judd. No, I don't need to include <cstdio>, <vector>, and <algorithm> here. They were just in my project template, so forgot to delete it. :) :) And thanks for the complement.

Write a 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.