Advertisement
Josif_tepe

Untitled

Jan 26th, 2025
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int rek(int x) {
  5.     if(x == 0) {
  6.         return 0;
  7.     }
  8.     int cifra = x % 10;
  9.     if(cifra % 2 == 0) {
  10.         return rek(x / 10) + cifra;
  11.     }
  12.     else {
  13.         return rek(x / 10);
  14.     }
  15. }
  16. int main() {
  17.     int n;
  18.     cin >> n;
  19.    
  20.     cout << rek(n) << endl;
  21.     return 0;
  22. }
  23. /*
  24.  rek(1234) = rek(123) + 4 = 2 + 4 = 6
  25.  rek(123) = rek(12) = 2
  26.  rek(12) = rek(1) + 2 = 0 + 2 = 2
  27.  rek(1) = rek(0) = 0
  28.  rek(0) = 0
  29.  
  30.  **/
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement