Horje
1281. Subtract the Product and Sum of Digits of an Integer leetcode solution in c++ Code Example
1281. Subtract the Product and Sum of Digits of an Integer leetcode solution in c++
#include<iostream>
using namespace std;

class Solution {
public:
	int subtractProductAndSum(int n) {
		int product = 1;
		int sum = 0;
		while (n != 0)
		{
			product *= (n % 10);
			sum += (n % 10);
			n /= 10;
		}
		return product - sum;
	}
};

int main()
{
	int n;
	cin >> n;
	Solution ss;
	cout << ss.subtractProductAndSum(n) << "\n";
	return 0;
}




Cpp

Related
cpp print variable value Code Example cpp print variable value Code Example
c++ how to check whether a file exists? Code Example c++ how to check whether a file exists? Code Example
exit: redefinition; '__declspec(noreturn)' or '[[noreturn]]' Code Example exit: redefinition; '__declspec(noreturn)' or '[[noreturn]]' Code Example
cpp-variadics/problem? Code Example cpp-variadics/problem? Code Example
Buy 2 Get 1 Free codechef solution in c++ Code Example Buy 2 Get 1 Free codechef solution in c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
14