Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int rec(int x) {
- if(x == 0) {
- return 0;
- }
- int cifra = x % 10;
- if(cifra % 2 == 0) {
- return rec(x / 10) + 1;
- }
- else {
- return rec(x / 10) + 0;
- }
- }
- int main() {
- int r = rec(1234);
- cout << r << endl;
- return 0;
- }
- // rec(1234) = rec(123) + 1 = 1 + 1 = 2
- // rec(123) = rec(12) = 1
- // rec(12) = rec(1) + 1 = 0 + 1 = 1
- // rec(1) = rec(0) = 0
- // rec(0) = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement