Explicitly handle first digit and call recursive function countRec for remaining digits . Note that the first digit is considered as even digit .
for ( int i = 1 ; i <= 9 ; i ++ ) ans += countRec ( digits + 1 , esum + i , osum , true , n ) ; return ans ; }