1 #include<iostream> 2 #include<ctime> 3 using namespace std; 4 5 #define N 4 6 7 void fullarrange(char num[], int len, int index) { 8 if(index == len) { 9 cout << num << " "; 10 return; 11 } 12 for(int i = 0; i < 10; i++) { 13 num[index] = ‘0‘ + i; 14 fullarrange(num, len, index+1); 15 } 16 } 17 18 int main() 19 { 20 char num[N]; 21 memset(num, ‘0‘, N); 22 num[N-1] = ‘\0‘; 23 for(int i = 0; i < 10; i++) { 24 num[0] = i + ‘0‘; 25 fullarrange(num, N-1, 1); 26 } 27 return 0; 28 }
原文:http://www.cnblogs.com/wanghui390/p/3771908.html