Given an integer Y and a range [L, R], the task is to find the count of all numbers from the given range whose sum of digits is equal to Y.
Input: L = 0, R = 11, Y = 2
2 -> 2
11 -> 1 + 1 = 2
Input: L = 500, R = 1000, Y = 6
Approach: Initialize count = 0 and for every number from the range, calculate sum of it’s digits. If the digit sum is equal to Y then increment the count. Print the count in the end.
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 of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count all prime numbers in a given range whose sum of digits is also prime
- Count of n digit numbers whose sum of digits equals to given sum
- Count of numbers whose sum of increasing powers of digits is equal to the number itself
- Count of N digit Numbers whose sum of every K consecutive digits is equal
- Count of N digit Numbers whose sum of every K consecutive digits is equal | Set 2
- Print all n-digit numbers whose sum of digits equals to given sum
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- Count the numbers with N digits and whose suffix is divisible by K
- Count all N digit numbers whose digits are multiple of X
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Count numbers from range whose prime factors are only 2 and 3
- Count numbers from range whose prime factors are only 2 and 3 using Arrays | Set 2
- Minimum digits to be removed to make either all digits or alternating digits same
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.