27 -> 14 -> 4
The number of products necessary to reach the single-digit number is called the persistence number of that integer. Thus 715 and 88 have a persistence number of 3, while 27 has persistence 2. Make a program to find the only two-digit number with persistence greater than 3?
I was able to come up with a rough idea and the code is below but it doesn't seem to work:
> and the code is below
that seems to be python. we are a c++ forum.
> but it doesn't seem to work
be more descriptive
Look at your first condition if num1-10>10:
consider that `num' is 88, `num1' would be 64 and the condition would be met. So you print 'step2' and are done with it, but 88 was an step3.
I'll recommend you to make a function that computes the range instead to try to do it in the loop.
#include <iostream>
#include <string>
usingnamespace std;
int product( int );
int main()
{
string integer = "";
int number = 0;
cin >> number;
cout << product( number ) << endl;
system( "pause" );
return 0;
}
int product( int aNumber )
{
int result = 1;
string strNumber = std::to_string( aNumber );
for ( int i = 0; i < strNumber.length(); i++ )
result *= ( strNumber[i] - '0' );
return result;
}