#include <iostream>
usingnamespace std;
int prod( int n ) { return n < 10 ? n : prod( n / 10 ) * ( n % 10 ); }
int main()
{
int N = 10, a = 1; cout << a << ' ';
while( --N ) cout << ( a += prod( a ) ) << ' ';
}
talal02 wrote:
What's wrong in my code?
(1) You haven't given enough of it to compile.
(2) @cool123dude gives an infinitely better explanation of the logic (and is what I coded off).
(3) You presume that your numbers are two digits.
(4) You calculate those digits incorrectly; even if numbers were only 2 digits (which isn't many of them) then the first digit would be x / 10 and the second would be x % 10 ... but most won't be 2 digits anyway, so this won't work very well.