Advertisement
Josif_tepe

Untitled

May 12th, 2025
132
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.  
  5. int rec(int x) {
  6.     if(x == 0) {
  7.         return 0;
  8.     }
  9.     int cifra = x % 10;
  10.    
  11.     if(cifra % 2 == 0) {
  12.         return rec(x / 10) + 1;
  13.     }
  14.     else {
  15.         return rec(x / 10) + 0;
  16.     }
  17. }
  18. int main() {
  19.     int r = rec(1234);
  20.     cout << r << endl;
  21.     return 0;
  22. }
  23. // rec(1234) = rec(123) + 1 = 1 + 1 = 2
  24. // rec(123) = rec(12) = 1
  25. // rec(12) = rec(1) + 1 = 0 + 1 = 1
  26. // rec(1) = rec(0) = 0
  27. // rec(0) = 0
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement