Wednesday, 11 December 2019

1281. Subtract the Product and Sum of Digits of an Integer


/*
Tanzila Islam
Website: https://sites.google.com/site/tanzilamohita
Email: tanzilamohita@gmail.com
*/

#include <bits/stdc++.h>
using namespace std;

int subtractProductAndSum(int n) {
    int sum = 0;
    int product = 1;

	while(n>0){
    	sum += n % 10;
    	product *= n % 10;
    	n /= 10;
	}
	return product - sum;
}

int main() {
	int n;
	cout << "Input: ";
	cin >> n;
	cout << "Output " << subtractProductAndSum(n) << endl;
	return 0;
}

No comments:

Post a Comment