输入数字n,按顺序从打印出从1到最大的n位十进制数.比如输入3,也就是最大的3位数是999,那么就打印1.2.3.---999;
方法1:非递归
1 #include "stdafx.h" 2 #include <iostream> 3 #include <exception> 4 using namespace std; 5 void PrintNumber(char* number) 6 { 7 bool isBeginning0 = true; 8 int nLength = strlen(number); 9 for(int i = 0;i<nLength;++i) 10 { 11 if(isBeginning0&&number[i]!='0') 12 isBeginning0 = false; 13 if(!isBeginning0) 14 { 15 printf("%c",number[i]); 16 } 17 18 } 19 printf(" "); 20 } 21 bool Increment(char* number) 22 { 23 bool isOverflow = false; 24 int nTakeOver = 0; 25 int nLength = strlen(number); 26 for(int i = nLength-1;i>=0;i--){ 27 int nSum = number[i]-'0'+nTakeOver; 28 if(i==nLength-1) 29 nSum++; 30 if(nSum>=10) 31 { 32 if(i==0) 33 isOverflow=true; 34 else 35 { 36 nSum -= 10; 37 nTakeOver=1; 38 number[i]='0'+nSum; 39 40 } 41 } 42 else{ 43 number[i]='0'+nSum; 44 break; 45 } 46 } 47 return isOverflow; 48 49 } 50 void PrintToMaxOfNDigits(int n) 51 { 52 if(n<=0) 53 return; 54 char *number = new char[n+1]; 55 memset(number,'0',n); 56 number[n]='