sichtbar machen
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:e0dea4ed78aa
- Child:
- 2:5fd21c59f63c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 21 18:31:26 2020 +0000 @@ -0,0 +1,58 @@ +/* + +Übung für Bulme: + +#141 Beharrlichkeit natürlicher Zahlen +von der Web-Seite: +https://trainyourprogrammer.de/index.pl?page=cplusplus&seite=12#for_scrollposition + +*/ + +#include <iostream> +#include <cmath> + +using std::cout; +using std::endl; + +size_t multipleDigits(size_t number_to_mult) +{ + size_t result = 1; + size_t rest = 0; + while(number_to_mult) + { + rest = number_to_mult % 10; + result *= rest; + if (rest == 0) + { + return 0; + } + number_to_mult /= 10; + } + return result; +} + +int main(int argc, char const *argv[]) +{ + size_t MAX = pow(9, 6); + size_t current_persintence = 0; + size_t persistance_max = 0; + size_t persist_number_max = 0; + size_t current_num; + for (size_t i = 11; i <= MAX; i++) + { + current_persintence = 0; + current_num = i; + do + { + current_num = multipleDigits(current_num); + ++current_persintence; + } while (current_num > 9); + if(persistance_max < current_persintence) + { + persistance_max = current_persintence; + persist_number_max = i; + } + } + std::cout << "number with the highest persistance is " << persist_number_max << std::endl; + return 0; +}