Advertisement
gosuodin

tong cac so le

Jun 20th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int sum(int n) {
  4. if (n < 0) {
  5. return -1;
  6. }
  7. else {
  8. if (n < 10) {
  9. if (n % 2 != 0) {
  10. return n;
  11. }
  12. else {
  13. return 0;
  14. }
  15. }
  16. else {
  17. if ((n % 10) % 2 != 0) {
  18. return n % 10 + sum(n / 10);
  19. }
  20. else {
  21. return sum(n / 10);
  22. }
  23.  
  24. }
  25.  
  26. }
  27.  
  28. }
  29. void main() {
  30. cout << sum(-21313213);
  31. system("pause");
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement