# Print from 1 to the largest n-bit decimal number

Question:

http://www.lintcode.com/en/problem/print-numbers-by-recursion/

Print numbers from 1 to the largest number with N digits by recursion.

Answer:

```
#include <iostream>
using namespace std;
void PrintNumber(char* number, int len) {
bool isb0 = true;
for (int i = 0; i < len; i++) {
if (isb0 && number[i] != '0')
isb0 = false;
if (!isb0)
cout << number[i];
}
cout << " ";
}
void Print1ToMaxRecurse(char* number, int length, int index) {
if (index == (length - 1)) {
PrintNumber(number, length);
return;
}
for (int i = 0; i < 10; i++) {
number[index+1] = i+'0';
Print1ToMaxRecurse(number, length, index+1);
}
}
void Print1ToMax(int n) {
if (n <= 0)
return;
char *number = new char[n+1];
number[n] = '\0';
for (int i = 0; i < 10; i++) {
number[0]=i+'0';
Print1ToMaxRecurse(number, n, 0);
}
cout << endl;
}
int main() {
int n;
cin >> n;
Print1ToMax(n);
return 0;
}
```