Odpowiedź:
#include <iostream>
int recursiveDigitNumber(int a) {
static int counter = 0;
if (a > 0) {
if (a % 10 == 2) {
counter++;
}
a /= 10;
return recursiveDigitNumber(a);
}
return counter;
}
int main() {
int number;
std::cin >> number;
std::cout << recursiveDigitNumber(number);
return 0;
}
Wyjaśnienie: