summaryrefslogtreecommitdiff
path: root/math
diff options
context:
space:
mode:
authorkittobi1992 <Tobias.Heuer@gmx.net>2014-11-10 14:09:32 +0100
committerkittobi1992 <Tobias.Heuer@gmx.net>2014-11-10 14:09:32 +0100
commit7490d63b4851079cb6302072294692ca55ceda59 (patch)
tree81fb42a53adba4f58b68ecf23517a8e7870e917e /math
parent9a0e44d7cba9084fb47361290c9c23d1ef5063e1 (diff)
Adding Program to calculate the binomial coefficient without overflow
Diffstat (limited to 'math')
-rw-r--r--math/binomial.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/math/binomial.cpp b/math/binomial.cpp
new file mode 100644
index 0000000..8cdd73a
--- /dev/null
+++ b/math/binomial.cpp
@@ -0,0 +1,21 @@
+#include <iostream>
+
+using namespace std;
+
+
+unsigned long long calc_binom(unsigned long long N, unsigned long long K)
+{
+ unsigned long long r = 1;
+ unsigned long long d;
+ if (K > N) return 0;
+ for (d = 1; d <= K; d++)
+ {
+ r *= N--;
+ r /= d;
+ }
+ return r;
+}
+
+
+}
+