Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int productOfNumbers(int n) {
  6. string str_n = to_string(n);
  7. int result = 1;
  8. for (char c : str_n) {
  9. if (c == '-') {
  10. result *= -1;
  11. continue;
  12. }
  13. result *= (c - '0');
  14. }
  15. return result;
  16. }
  17.  
  18. int main() {
  19. int n;
  20. cin >> n;
  21. cout << productOfNumbers(n) << endl;
  22.  
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement