Count numbers having 0 as a digit | Returns 1 if x has 0 , else 0 ; Traverse through all digits of x to check if it has 0. ; If current digit is 0 , return true ; Returns count of numbers from 1 to n with 0 as digit ; Initialize count of numbers having 0 as digit . ; Traverse through all numbers and for every number check if it has 0. ; Driver program
def has0 ( x ) : NEW_LINE INDENT while ( x != 0 ) : NEW_LINE INDENT if ( x % 10 == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT x = x // 10 NEW_LINE DEDENT return 0 NEW_LINE DEDENT def getCount ( n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT count = count + has0 ( i ) NEW_LINE DEDENT return count NEW_LINE DEDENT n = 107 NEW_LINE print ( " Count ▁ of ▁ numbers ▁ from ▁ 1" , " ▁ to ▁ " , n , " ▁ is ▁ " , getCount ( n ) ) NEW_LINE