Website Summary Files Commits Branches @commit @diff @stats
path: root / Week05 / Exercise21.cpp
diff options
context:
space:
mode:
1 files changed, 21 insertions, 0 deletions
-rw-r--r--Week05/Exercise21.cpp21
diff --git a/Week05/Exercise21.cpp b/Week05/Exercise21.cpp
new file mode 100644
index 0000000..1572372
--- /dev/null
+++ b/Week05/Exercise21.cpp
@@ -0,0 +1,21 @@
+#include <iostream>
+
+int main() {
+ unsigned int n;
+ std::cin >> n;
+
+ unsigned long f1 = 1, f2 = 1, f3 = 1;
+ for (unsigned long i = 1; i <= 2 * n; i++) {
+ f1 *= i;
+ if (i <= n + 1)
+ f2 *= i;
+ if (i <= n)
+ f3 *= i;
+ }
+
+ unsigned long catalan = f1 / (f2 * f3);
+
+ std::cout << catalan << std::endl;
+
+ return 0;
+}