Product of Digits of Three-Digit Number
Programming Basics · C++
TASK
Problem
In “Product of Digits of Three-Digit Number”, given the required decimal number, multiply its three digits.
EXAMPLE
Example
123
6
LIMITS
Constraints
The number has exactly the number of decimal digits stated in the task and is non-negative.
LEARN
Theory for this problem
+
Repeated division by powers of 10 and `% 10` isolate decimal digits without converting the number to a string.
Connection to “Product of Digits of Three-Digit Number”: here, integer `/` and `%` provide the quotient and remainder, which is useful for digit extraction and cyclic arithmetic.
NEED HELP?
Hints
+
['Extract the digits first, then combine or compare them.', 'After solving “Product of Digits of Three-Digit Number”, verify the algorithm on your own small example and on an allowed boundary case. Print only the required result with no extra text.']
ANSWER
Solution
+
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n / 100) * ((n / 10) % 10) * (n % 10) << '\n';
return 0;
}