sichtbar machen

Dependencies:   mbed

Committer:
kafka
Date:
Tue Apr 28 19:37:39 2020 +0000
Revision:
2:5fd21c59f63c
Parent:
0:e0dea4ed78aa
sichbar machen

Who changed what in which revision?

UserRevisionLine numberNew 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 2:5fd21c59f63c 9
kafka 0:e0dea4ed78aa 10 */
kafka 0:e0dea4ed78aa 11
kafka 0:e0dea4ed78aa 12 #include <iostream>
kafka 0:e0dea4ed78aa 13 #include <cmath>
kafka 0:e0dea4ed78aa 14
kafka 0:e0dea4ed78aa 15 using std::cout;
kafka 0:e0dea4ed78aa 16 using std::endl;
kafka 0:e0dea4ed78aa 17
kafka 0:e0dea4ed78aa 18 size_t multipleDigits(size_t number_to_mult)
kafka 0:e0dea4ed78aa 19 {
kafka 0:e0dea4ed78aa 20 size_t result = 1;
kafka 0:e0dea4ed78aa 21 size_t rest = 0;
kafka 0:e0dea4ed78aa 22 while(number_to_mult)
kafka 0:e0dea4ed78aa 23 {
kafka 0:e0dea4ed78aa 24 rest = number_to_mult % 10;
kafka 0:e0dea4ed78aa 25 result *= rest;
kafka 0:e0dea4ed78aa 26 if (rest == 0)
kafka 0:e0dea4ed78aa 27 {
kafka 0:e0dea4ed78aa 28 return 0;
kafka 0:e0dea4ed78aa 29 }
kafka 0:e0dea4ed78aa 30 number_to_mult /= 10;
kafka 0:e0dea4ed78aa 31 }
kafka 0:e0dea4ed78aa 32 return result;
kafka 0:e0dea4ed78aa 33 }
kafka 0:e0dea4ed78aa 34
kafka 0:e0dea4ed78aa 35 int main(int argc, char const *argv[])
kafka 0:e0dea4ed78aa 36 {
kafka 0:e0dea4ed78aa 37 size_t MAX = pow(9, 6);
kafka 0:e0dea4ed78aa 38 size_t current_persintence = 0;
kafka 0:e0dea4ed78aa 39 size_t persistance_max = 0;
kafka 0:e0dea4ed78aa 40 size_t persist_number_max = 0;
kafka 0:e0dea4ed78aa 41 size_t current_num;
kafka 0:e0dea4ed78aa 42 for (size_t i = 11; i <= MAX; i++)
kafka 0:e0dea4ed78aa 43 {
kafka 0:e0dea4ed78aa 44 current_persintence = 0;
kafka 0:e0dea4ed78aa 45 current_num = i;
kafka 0:e0dea4ed78aa 46 do
kafka 0:e0dea4ed78aa 47 {
kafka 0:e0dea4ed78aa 48 current_num = multipleDigits(current_num);
kafka 0:e0dea4ed78aa 49 ++current_persintence;
kafka 0:e0dea4ed78aa 50 } while (current_num > 9);
kafka 0:e0dea4ed78aa 51 if(persistance_max < current_persintence)
kafka 0:e0dea4ed78aa 52 {
kafka 0:e0dea4ed78aa 53 persistance_max = current_persintence;
kafka 0:e0dea4ed78aa 54 persist_number_max = i;
kafka 0:e0dea4ed78aa 55 }
kafka 0:e0dea4ed78aa 56 }
kafka 0:e0dea4ed78aa 57 std::cout << "number with the highest persistance is " << persist_number_max << std::endl;
kafka 0:e0dea4ed78aa 58 return 0;
kafka 0:e0dea4ed78aa 59 }