Enter N to print 1 to the maximum n decimal number sequentially

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.