Answers for "Given an integer number n, return the difference between the product of its digits and the sum of its digits."

0

Given an integer number n, return the difference between the product of its digits and the sum of its digits.

class Solution {
    public int subtractProductAndSum(int n) {
        int res=0;
        int p=1;
        int sum=0;
        while(n!=0){
            int r=n%10;
            n=n/10;
             p=p*r;
             sum+=r;
        }
        res=p-sum;
        return res;
    }
}
Posted by: Guest on April-02-2021

Code answers related to "Given an integer number n, return the difference between the product of its digits and the sum of its digits."

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language