Advertisement
gosuodin

%3

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