1281.cpp (287B)
1 class Solution { 2 public: 3 int subtractProductAndSum(int n) const { 4 int product = 1, sum = 0; 5 6 do { 7 const int digit = n % 10; 8 product *= digit; 9 sum += digit; 10 } while ((n /= 10) > 0); 11 12 return product - sum; 13 } 14 };