leetcode1281 整数的各位积和之差

class Solution {
public:
    int subtractProductAndSum(int n) {
        int add=0; int prod=1;
        while(n>0){
            int r=n%10;
            n/=10;
            prod*=r;
            add+=r;
        }
        int res=prod-add;
        return res;
    }
};

原文地址:https://www.cnblogs.com/joelwang/p/12009400.html