C Program to count the number of zeros from 0 to N
Input: N = 10
The number with zeros are 0, 10 till 10. Hence the count of zeros is 2.
Input: N = 20
The number with zeros are 0, 10, 20 till 20. Hence the count of zeros is 3.
- Iterate from 0 to N.
- For each number do the following:
- Store the above number in a variable temp.
- For each digit in temp, if the digit is zero then increment the zero count by 1.
- Print the count of zeros calculated in the above steps.
Below is the implementation of the above approach:
Time Complexity: O(N)
Auxiliary Space: O(1)
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.