Press "Enter" to skip to content

How to Print N Integers in String Order

Ajk 0

So the purpose of this question is to print out N integers in String Order. For example, if N is 1000, then we will output: 1, 10, 100, 1000, 101, 102, … 109, 11, 110, …

First off we are going to run off an assumption given in the example. We are printing only positive integers!.
Secondly, let’s try to examine what is happening here. We need to print lower digit numbers first and then all numbers formed of this number + attached 1-10. Seeing as this is a recurring action that we do, a recursive algorithm would fit perfectly!

From this we can have the following recursive algorithm:

  • Main method – loop through 1 to 9
  • Recursive method – print current number, + current number + an in order number from 1-10

Printing N Integers in String Order – first and final try

Great! Now we all know how to print N Integers in String Order! A quick editing of the algorithm, makes sure that we do not go over our N numners.
Hope you guys enjoyed it… and I’ll see you guys next time ;D

The following two tabs change content below.
If you like one of my posts the best way to support is give it a thumbs up, comment, or share it on social media 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *