Advertisement
itanev

Untitled

Mar 19th, 2023 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int MultipliedSum(int odd, int even){
  5. return odd * even;
  6. }
  7.  
  8. int EvenOrOdd(int singles){
  9.  
  10. //checking if the digit is odd or even
  11. return singles % 2;
  12. }
  13.  
  14. int main()
  15. {
  16. int num = -12345;
  17. // cin >> num;
  18.  
  19. int evenSum, oddSum, singles = 0;
  20.  
  21. while (num)
  22. {
  23. singles = num % 10; //getting the last digit from the number
  24.  
  25. if ( EvenOrOdd(singles) )
  26. {
  27. evenSum += singles;
  28. }
  29. else
  30. {
  31. oddSum += singles;
  32. }
  33.  
  34. num /= 10; // removing the last digit from the number
  35. }
  36.  
  37. cout << MultipliedSum(oddSum, evenSum);
  38.  
  39. return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement