Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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) << "
";
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to display score using SDL in c++ 
Cpp :: calculate number of edges of graph in data structure c++ 
Cpp :: vector.rbegin() 
Cpp :: Codeforces Round #376 (Div. 2), problem: (A) Night at the Museum 
Cpp :: c++ n in regex 
Cpp :: online c++ graphics compiler 
Cpp :: Change Font ImGui 
Cpp :: how to get the last digit of a number 
Cpp :: C++ bool 
Cpp :: c++ to c converter 
Cpp :: prime template c++ 
Cpp :: nlohmann json, writing to json file 
Cpp :: intage1 was not declared in this scope C++ 
Cpp :: how to run a cpp file in visual studio 
Cpp :: c++ is nan 
Cpp :: palindrome no example 
Cpp :: c++ permutation 
Cpp :: use of strtok 
Cpp :: insert into a vector more than once c++ 
Cpp :: sinonimo de tratar 
C :: run time in c 
C :: c get time in milliseconds 
C :: haskell print 
C :: string to int c 
C :: bash convert find to array 
C :: how to genrate a random number in C 
C :: c language append line to file 
C :: how to turn off zsh 
C :: typedef pointer 
C :: c if else 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =