Given an integer N greater than 0, the task is to find the occurrence of digit K present in the given number N.
Input: N = 10000, K = 0
Occurrence of ‘0’ digit in 10000 is 4.
Input: N = 51435, K = 5
Occurrence of ‘5’ digit in 51435 is 2
Approach: The idea is to use recursion to extract the least significant digit of the number in each step and Check that the digit extracted is equal to the given digit K or not. Finally, recurse for checking the next digits of the number by computing the integer division of that number by 10.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Sum of digit of a number using recursion
- Add the given digit to a number stored in a linked list using recursion
- Perform n steps to convert every digit of a number in the format [count][digit]
- Count of Numbers in Range where first digit is equal to last digit of the number
- Count Set-bits of number using Recursion
- First occurrence of a digit in a given fraction
- Count the number of occurrences of a particular digit in a number
- Count n digit numbers divisible by given number
- Count numbers with difference between number and its digit sum greater than specific value
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- 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
- Count 'd' digit positive integers with 0 as a digit
- Count n digit numbers not having a particular digit
- Count the occurrence of Nth term in first N terms of Van Eck's sequence
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- 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
- Largest number less than N with digit sum greater than the digit sum of N
- Count of subsets with sum equal to X using Recursion
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.
Improved By : Akanksha_Rai