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 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; char NthCharacter ( int n ) { string s = " " ; int c = 1 ; for ( int i = 1 ; ; i ++ ) { if ( c < 10 ) s += char ( 48 + c ) ; else { string s1 = " " ; int dup = c ; while ( dup ) { s1 += char ( ( dup % 10 ) + 48 ) ; dup /= 10 ; } reverse ( s1 . begin ( ) , s1 . end ( ) ) ; s += s1 ; } c ++ ; if ( s . length ( ) >= n ) { return s [ n - 1 ] ; } } } int main ( ) { int n = 11 ; cout << NthCharacter ( n ) ; return 0 ; }