Smallest odd digits number not less than N | function to check if all digits are odd of a given number ; iterate for all digits ; if digit is even ; all digits are odd ; function to return the smallest number with all digits odd ; iterate till we find a number with all digits odd ; Driver Code
< ? php function check_digits ( $ n ) { while ( $ n > 1 ) { if ( ( $ n % 10 ) % 2 == 0 ) return 0 ; $ n = ( int ) $ n / 10 ; } return 1 ; } function smallest_number ( $ n ) { for ( $ i = $ n ; ; $ i ++ ) if ( check_digits ( $ i ) ) return $ i ; } $ N = 2397 ; echo smallest_number ( $ N ) ; ? >