aboutsummaryrefslogtreecommitdiff
path: root/challenge-108/ulrich-rieke/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-108/ulrich-rieke/cpp')
-rw-r--r--challenge-108/ulrich-rieke/cpp/ch-1.cpp10
-rw-r--r--challenge-108/ulrich-rieke/cpp/ch-2.cpp26
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-108/ulrich-rieke/cpp/ch-1.cpp b/challenge-108/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..e8d0b8b2fe
--- /dev/null
+++ b/challenge-108/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,10 @@
+#include <vector>
+#include <iostream>
+#include <string>
+
+int main( ) {
+ std::vector<std::string> cities { "Amsterdam" , "Berlin" , "Moscow" } ;
+ std::cout << "The vector cities is located at " << &cities << " !\n" ;
+ std::cout << "Its memory size is " << sizeof( cities ) << " !\n" ;
+ return 0 ;
+}
diff --git a/challenge-108/ulrich-rieke/cpp/ch-2.cpp b/challenge-108/ulrich-rieke/cpp/ch-2.cpp
new file mode 100644
index 0000000000..5d39d4793d
--- /dev/null
+++ b/challenge-108/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,26 @@
+#include <vector>
+#include <iostream>
+
+int main( ) {
+ std::vector<int> bellnumbers { 1 } ;
+ std::vector<int> currentRow ;
+ std::vector<int> previousRow { 1 } ;
+ while ( bellnumbers.size( ) < 10 ) {
+ currentRow.push_back( previousRow.back( )) ;
+ int currentIndex = 0 ;
+ while ( currentRow.size( ) < ( previousRow.size( ) + 1 ) ) {
+ currentIndex++ ;
+ currentRow.push_back( currentRow[ currentIndex - 1 ] +
+ previousRow[ currentIndex - 1 ] ) ;
+ }
+ bellnumbers.push_back( *(currentRow.begin( ) ) ) ;
+ previousRow = currentRow ;
+ currentRow.clear( ) ;
+ }
+ std::cout << "These are the first 10 Bell numbers:\n" ;
+ for ( int i = 1 ; i < 10 ; i++ ) {
+ std::cout << " " << i << " : " << bellnumbers[ i - 1 ] << '\n' ;
+ }
+ std::cout << 10 << " : " << bellnumbers[9] << '\n' ;
+ return 0 ;
+}