Given a number N and a digit D, the task is to count the occurrences of D in N.
Input: N = 25, D = 2 Output: 1 Input: N = 100, D = 0 Output: 2
Approach: Take out the digits one by one in N and check if this digit is equal to D. If equal, then increment the count by 1. In the end, print the count.
Below is the implementation of the above approach:
- Number of occurrences of 2 as a digit in numbers from 0 to n
- Count of Numbers in Range where first digit is equal to last digit of the number
- Count digit groupings of a number with given constraints
- Count n digit numbers divisible by given number
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- Count numbers with difference between number and its digit sum greater than specific value
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Queries on sum of odd number digit sums of all the factors of a number
- Find the remainder when First digit of a number is divided by its Last digit
- Largest number less than N whose each digit is prime number
- Largest number less than N with digit sum greater than the digit sum of N
- Find the occurrences of digit d in the range [0..n]
- Number of occurrences of a given angle formed using 3 vertices of a n-sided regular polygon
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.