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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count n digit numbers not having a particular digit
- Count of N-digit numbers having digit XOR as single digit
- Number of occurrences of 2 as a digit in numbers from 0 to n
- Find the occurrences of digit d in the range [0..n]
- Count of Numbers in Range where first digit is equal to last digit of the number
- Count 'd' digit positive integers with 0 as a digit
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Count of pairs (A, B) in range 1 to N such that last digit of A is equal to the first digit of B
- Check whether an array of strings can correspond to a particular number X
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Seating arrangement of N boys sitting around a round table such that two particular boys sit together
- Total ways of selecting a group of X men from N men with or without including a particular man
- Largest number less than N with digit sum greater than the digit sum of N
- Find the remainder when First digit of a number is divided by its Last digit
- Last digit of a number raised to last digit of N factorial
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Check if frequency of each digit is less than the digit
- Generate array having differences between count of occurrences of every array element on its left and right
- 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.