---
# System prepended metadata

title: '[1281. Subtract the Product and Sum of Digits of an Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/)'

---

# [1281. Subtract the Product and Sum of Digits of an Integer](https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/)
![](https://i.imgur.com/b15lC9F.png)
![](https://i.imgur.com/MQiysUF.png)


int subtractProductAndSum(int n){
    int max=n;
    int number;
    int product=1;
    int sum=0;
    for(int i=10;i<max*10;i*=10)
    {
        number=n%10;
        n=n/10;
        product*=number;
        sum+=number;
    }
    int answer=product-sum;
    if(answer==1)
    {
        answer=0;
    }
    return answer;
}