/**********************************************
The function length(int n) is a recursive
function that returns the number of characters
needed to print out n.
 **********************************************/
#include <iostream>
using namespace std;

int length(int);

int main()
{
  // Get integer n
  int n;
  cout << "Enter integer: ";
  cin >> n;

  // Print out number of characters in n
  cout << "Printing " << n << " takes "
       << length(n) << " characters!" << endl;

  return 0;
}

int length(int n)
{
  if (n < 0)
    return 1 + length(-n);  // negatives!
  else if (n < 10)
    return 1;               // single digits! (base case)
  else
    return 1 + length(n/10);// multiple digit positive!
}