sichtbar machen
Dependencies: mbed
main.cpp@0:e0dea4ed78aa, 2020-04-21 (annotated)
- Committer:
- kafka
- Date:
- Tue Apr 21 18:31:26 2020 +0000
- Revision:
- 0:e0dea4ed78aa
- Child:
- 2:5fd21c59f63c
aufgabe
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kafka | 0:e0dea4ed78aa | 1 | /* |
kafka | 0:e0dea4ed78aa | 2 | |
kafka | 0:e0dea4ed78aa | 3 | Übung für Bulme: |
kafka | 0:e0dea4ed78aa | 4 | |
kafka | 0:e0dea4ed78aa | 5 | #141 Beharrlichkeit natürlicher Zahlen |
kafka | 0:e0dea4ed78aa | 6 | von der Web-Seite: |
kafka | 0:e0dea4ed78aa | 7 | https://trainyourprogrammer.de/index.pl?page=cplusplus&seite=12#for_scrollposition |
kafka | 0:e0dea4ed78aa | 8 | |
kafka | 0:e0dea4ed78aa | 9 | */ |
kafka | 0:e0dea4ed78aa | 10 | |
kafka | 0:e0dea4ed78aa | 11 | #include <iostream> |
kafka | 0:e0dea4ed78aa | 12 | #include <cmath> |
kafka | 0:e0dea4ed78aa | 13 | |
kafka | 0:e0dea4ed78aa | 14 | using std::cout; |
kafka | 0:e0dea4ed78aa | 15 | using std::endl; |
kafka | 0:e0dea4ed78aa | 16 | |
kafka | 0:e0dea4ed78aa | 17 | size_t multipleDigits(size_t number_to_mult) |
kafka | 0:e0dea4ed78aa | 18 | { |
kafka | 0:e0dea4ed78aa | 19 | size_t result = 1; |
kafka | 0:e0dea4ed78aa | 20 | size_t rest = 0; |
kafka | 0:e0dea4ed78aa | 21 | while(number_to_mult) |
kafka | 0:e0dea4ed78aa | 22 | { |
kafka | 0:e0dea4ed78aa | 23 | rest = number_to_mult % 10; |
kafka | 0:e0dea4ed78aa | 24 | result *= rest; |
kafka | 0:e0dea4ed78aa | 25 | if (rest == 0) |
kafka | 0:e0dea4ed78aa | 26 | { |
kafka | 0:e0dea4ed78aa | 27 | return 0; |
kafka | 0:e0dea4ed78aa | 28 | } |
kafka | 0:e0dea4ed78aa | 29 | number_to_mult /= 10; |
kafka | 0:e0dea4ed78aa | 30 | } |
kafka | 0:e0dea4ed78aa | 31 | return result; |
kafka | 0:e0dea4ed78aa | 32 | } |
kafka | 0:e0dea4ed78aa | 33 | |
kafka | 0:e0dea4ed78aa | 34 | int main(int argc, char const *argv[]) |
kafka | 0:e0dea4ed78aa | 35 | { |
kafka | 0:e0dea4ed78aa | 36 | size_t MAX = pow(9, 6); |
kafka | 0:e0dea4ed78aa | 37 | size_t current_persintence = 0; |
kafka | 0:e0dea4ed78aa | 38 | size_t persistance_max = 0; |
kafka | 0:e0dea4ed78aa | 39 | size_t persist_number_max = 0; |
kafka | 0:e0dea4ed78aa | 40 | size_t current_num; |
kafka | 0:e0dea4ed78aa | 41 | for (size_t i = 11; i <= MAX; i++) |
kafka | 0:e0dea4ed78aa | 42 | { |
kafka | 0:e0dea4ed78aa | 43 | current_persintence = 0; |
kafka | 0:e0dea4ed78aa | 44 | current_num = i; |
kafka | 0:e0dea4ed78aa | 45 | do |
kafka | 0:e0dea4ed78aa | 46 | { |
kafka | 0:e0dea4ed78aa | 47 | current_num = multipleDigits(current_num); |
kafka | 0:e0dea4ed78aa | 48 | ++current_persintence; |
kafka | 0:e0dea4ed78aa | 49 | } while (current_num > 9); |
kafka | 0:e0dea4ed78aa | 50 | if(persistance_max < current_persintence) |
kafka | 0:e0dea4ed78aa | 51 | { |
kafka | 0:e0dea4ed78aa | 52 | persistance_max = current_persintence; |
kafka | 0:e0dea4ed78aa | 53 | persist_number_max = i; |
kafka | 0:e0dea4ed78aa | 54 | } |
kafka | 0:e0dea4ed78aa | 55 | } |
kafka | 0:e0dea4ed78aa | 56 | std::cout << "number with the highest persistance is " << persist_number_max << std::endl; |
kafka | 0:e0dea4ed78aa | 57 | return 0; |
kafka | 0:e0dea4ed78aa | 58 | } |