Print all numbers from a given range that are made up of consecutive digits | C # program for the above approach ; Function to find the consecutive digit numbers in the given range ; Initialize num as empty String ; Stores the resultant number ; Iterate over the range [ 1 , 9 ] ; Check if the current number is within range ; Iterate on the digits starting from i ; Checking the consecutive digits numbers starting from i and ending at j is within range or not ; Sort the numbers in the increasing order ; Print the required numbers ; Driver code
using System ; using System . Collections . Generic ; class Program { static void solve ( int start , int end ) { string num = " " ; List < int > ans = new List < int > ( ) ; for ( int i = 1 ; i <= 9 ; i ++ ) { num = i . ToString ( ) ; int value = i ; if ( value >= start && value <= end ) { ans . Add ( value ) ; } for ( int j = i + 1 ; j <= 9 ; j ++ ) { num += j . ToString ( ) ; value = Int32 . Parse ( num ) ; if ( value >= start && value <= end ) { ans . Add ( value ) ; } } } ans . Sort ( ) ; foreach ( int it in ans ) Console . Write ( it + " ▁ " ) ; } static void Main ( ) { int L = 12 , R = 87 ; solve ( L , R ) ; } }