N | C # program to find the N - th character in the string "1234567891011 . . " ; Function that returns the N - th character ; initially null string ; starting integer ; add integers in string ; one digit numbers added ; more than 1 digit number , generate equivalent number in a string s1 and concatenate s1 into s . ; add the number in string ; reverse the string ; attach the number ; if the length exceeds N ; Utility reverse function ; Driver Code
using System ; class GFG { static char NthCharacter ( int n ) { String s = " " ; int c = 1 ; for ( int i = 1 ; ; i ++ ) { if ( c < 10 ) s += c . ToString ( ) ; else { String s1 = " " ; int dup = c ; while ( dup > 0 ) { s1 += ( dup % 10 ) . ToString ( ) ; dup /= 10 ; } String temp = reverse ( s1 ) ; s += temp ; } c ++ ; if ( s . Length >= n ) { return s [ n - 1 ] ; } } } static String reverse ( String input ) { char [ ] a = input . ToCharArray ( ) ; int l , r = 0 ; r = a . Length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . Join ( " " , a ) ; } public static void Main ( String [ ] args ) { int n = 11 ; Console . WriteLine ( NthCharacter ( n ) ) ; } }