Subtract Product and Sum of digits of an integer
Anonymous
c_cpp
02/20/2024 1:41 PM
456 B
24
Indexable
class Solution {
public:
int subtractProductAndSum(int n) {
int product = 1;
int sum = 0;
while(n!=0){
int digit = n%10;
product *= digit;
sum += digit;
n = n/10;
}
int ans = product - sum;
return ans;
}
};Editor is loading...
Leave a Comment