If current position is 1 , then any digit from [ 1 - 9 ] can be placed . If n = 1 , 0 can be also placed .
if ( digit == 1 ) { for ( int i = ( n == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , n ) ; } }