Count how many integers from 1 to N contains 0’s as a digit.
Input: n = 9 Output: 0 Input: n = 107 Output: 17 The numbers having 0 are 10, 20,..90, 100, 101..107 Input: n = 155 Output: 24 The numbers having 0 are 10, 20,..90, 100, 101..110, 120, ..150.
The idea is to traverse all numbers from 1 to n. For every traversed number, traverse through its digits, if any digit is 0, increment count. Below is the implementation of the above idea :
Count of numbers from 1 to 107 is 17
Refer below post for optimized solution.
This article is contributed by Dheeraj Gupta. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Count digits in a factorial | Set 2
- How to swap two numbers without using a temporary variable?
- Lucky Numbers
- Ugly Numbers
- Write a program to add two numbers in base 14
- Count of Binary Digit numbers smaller than N
- Program for Fibonacci numbers
- Average of a stream of numbers
- Add two numbers without using arithmetic operators
- To find sum of two numbers without using any operator
- Count numbers that don't contain 3
- Count the number of possible triangles
- Count numbers with same first and last digits
- Count digits in given number N which divide N
- Russian Peasant (Multiply two numbers using bitwise operators)
Improved By : Sam007