sichtbar machen

Dependencies:   mbed

main.cpp

Committer:
kafka
Date:
2020-04-28
Revision:
2:5fd21c59f63c
Parent:
0:e0dea4ed78aa

File content as of revision 2:5fd21c59f63c:

/*

Ü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;
}