Given a positive integer N. The task is to find sum and product of digits of the number which evenly divides the number n.
Input: N = 12 Output: Sum = 3, product = 2 1 and 2 divide 12. So, their sum is 3 and product is 2. Input: N = 1012 Output: Sum = 4, product = 2 1, 1 and 2 divide 1012.
Approach: The idea is to find the each digit of the number n by modulus 10 and then check whether it divides n or not. Accordingly, add it to the sum and multiply it with the product. Notice that the digit can be 0, so take care of that case.
Below is the implementation of the above approach:
Sum = 4 Product = 2
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find count of digits in a number that divide the number
- Check if all digits of a number divide it
- Count digits in given number N which divide N
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Divide a number into two parts such that sum of digits is maximum
- Number of digits in the product of two numbers
- Program to calculate product of digits of a number
- Maximum sum and product of the M consecutive digits in a number
- Smallest number k such that the product of digits of k is equal to n
- Find the number in a range having maximum product of the digits
- Check if product of digits of a number at even and odd places is equal
- Check whether product of digits at even places of a number is divisible by K
- Maximum of sum and product of digits until number is reduced to a single digit
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find smallest number with given number of digits and sum of digits under given constraints