1 /*2 * Title: Enter N, sequentially print 1 to the maximum n decimal number3 * For example: Enter 3, then print,... 9994 * Update Date: 2015-06-155 */6 7 //note the traps in the topic, when n is slightly larger, it overflows, so the strategy of using the string output8 9#include <iostream>Ten using namespacestd; One A void -Print_number_byte (unsignedCharnum) - { the if(num<1)return ; - Charnum_ch[ One]="0123456789"; -UnsignedCharNp[num]; - + for(intI=0; i<num;i++) - { +np[i]=0; A } at while(1) - { - for(intI=0; i<num;i++)//Show Data - { -cout<<Num_ch[np[i]]; - } incout<<","; - if(np[num-1]==9) to{//Rounding Problem +np[num-1]=0; - for(inti=num-2; i>=0; i--) the{//until I met the first one, not 9. * if(np[i]==9) $ {Panax Notoginseng if(i==0)return ; -np[i]=0; the Continue; + } A Else the { +np[i]++; - Break; $ } $ } - } - Elsenp[num-1]++; the } - }Wuyi the intMainintargcChar*argv[]) - { WuUnsignedCharnum=4; - print_number_byte (num); About}
Enter N to print 1 to the maximum n decimal number sequentially