aboutsummaryrefslogtreecommitdiff
path: root/challenge-153/ulrich-rieke/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-02-21 20:24:43 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-02-21 20:24:43 +0000
commit67cae0ac5fd06c1bbb42b64a7682889e339c9676 (patch)
tree3a6e05333a6cf757082f386c56736c664412f96a /challenge-153/ulrich-rieke/cpp/ch-1.cpp
parent9a09829259c888940dc5f171348777b34dd91cd3 (diff)
downloadperlweeklychallenge-club-67cae0ac5fd06c1bbb42b64a7682889e339c9676.tar.gz
perlweeklychallenge-club-67cae0ac5fd06c1bbb42b64a7682889e339c9676.tar.bz2
perlweeklychallenge-club-67cae0ac5fd06c1bbb42b64a7682889e339c9676.zip
- Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-153/ulrich-rieke/cpp/ch-1.cpp')
-rw-r--r--challenge-153/ulrich-rieke/cpp/ch-1.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-153/ulrich-rieke/cpp/ch-1.cpp b/challenge-153/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..990ee9c29a
--- /dev/null
+++ b/challenge-153/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,28 @@
+#include <iostream>
+
+int factorial( int num ) {
+ if ( num == 0 ) {
+ return 1 ;
+ }
+ else {
+ int fac = 1 ;
+ for ( int i = 1 ; i < num + 1 ; i++ )
+ fac *= i ;
+ return fac ;
+ }
+}
+
+int leftFactorial( int n ) {
+ int sum = 0 ;
+ for ( int i = 0 ; i < n + 1 ; i++ )
+ sum += factorial( i ) ;
+ return sum ;
+}
+
+int main( ) {
+ for ( int i = 0 ; i < 10 ; i++ ) {
+ std::cout << leftFactorial( i ) << " " ;
+ }
+ std::cout << std::endl ;
+ return 0 ;
+}