If index = 1 , any digit from [ 1 - 9 ] can be placed . If N = 1 , 0 also can be placed .
if ( index == 1 ) { for ( int digit = ( N == 1 ? 0 : 1 ) ; digit <= 9 ; ++ digit ) { val += countOfNumbers ( index + 1 , sum + digit , N ) ; } }