// Prints out values of a function 'threemap' #include using namespace std; int threemap (int n) { if (n%2) // n is odd return (3*n+1); else // n is even return (n/2) ; } // This function assumes positive n int sumsquaredigits (int n) { int answer = 0 , rem ; while ( n > 0 ) { rem = n%10 ; // the remainder is the next digit (Reading from the right) answer += rem * rem ; n = n/10 ; } return answer ; } void printout( int (*func)(int) , int xmin=1 , int xmax=120 ) { for ( int x = xmin ; x <= xmax ; x ++ ) { cout << x << " " << func( x ) << endl ; } } void iterate( int (*func)(int) , int x=67 , int I=1000 ) { for ( int i = 0 ; i <= I ; i ++ ) { cout << i << " " << x << endl ; x = func( x ); } } int main() { int answer; cerr << "Choose threemap(0) or sumsquaredigits(1): " ; cin >> answer ; int N; cerr << "Choose initial condition: " ; cin >> N ; if(answer) iterate( sumsquaredigits , N ) ; else iterate( threemap , N ) ; return 0; }