#include <iostream>
// Recursive function to count even numbers in the array
int countEven(int arr[], int size) {
// Base case: if the size is 0, return 0
if (size == 0) {
return 0;
}
// Check if the last element is even
int isEven = (arr[size - 1] % 2 == 0) ? 1 : 0;
// Recursive call for the rest of the array
return isEven + countEven(arr, size - 1);
}
int main() {
int a[] = {1, 4, 6, 3, 7, 11, 8, 9, 10};
int size = sizeof(a) / sizeof(a[0]);
int evenCount = countEven(a, size);
std::cout << "The count of even numbers in the array is: " << evenCount << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKLy8gUmVjdXJzaXZlIGZ1bmN0aW9uIHRvIGNvdW50IGV2ZW4gbnVtYmVycyBpbiB0aGUgYXJyYXkKaW50IGNvdW50RXZlbihpbnQgYXJyW10sIGludCBzaXplKSB7CiAgICAvLyBCYXNlIGNhc2U6IGlmIHRoZSBzaXplIGlzIDAsIHJldHVybiAwCiAgICBpZiAoc2l6ZSA9PSAwKSB7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CiAgICAKICAgIC8vIENoZWNrIGlmIHRoZSBsYXN0IGVsZW1lbnQgaXMgZXZlbgogICAgaW50IGlzRXZlbiA9IChhcnJbc2l6ZSAtIDFdICUgMiA9PSAwKSA/IDEgOiAwOwogICAgCiAgICAvLyBSZWN1cnNpdmUgY2FsbCBmb3IgdGhlIHJlc3Qgb2YgdGhlIGFycmF5CiAgICByZXR1cm4gaXNFdmVuICsgY291bnRFdmVuKGFyciwgc2l6ZSAtIDEpOwp9CgppbnQgbWFpbigpIHsKICAgIGludCBhW10gPSB7MSwgNCwgNiwgMywgNywgMTEsIDgsIDksIDEwfTsKICAgIGludCBzaXplID0gc2l6ZW9mKGEpIC8gc2l6ZW9mKGFbMF0pOwogICAgCiAgICBpbnQgZXZlbkNvdW50ID0gY291bnRFdmVuKGEsIHNpemUpOwogICAgCiAgICBzdGQ6OmNvdXQgPDwgIlRoZSBjb3VudCBvZiBldmVuIG51bWJlcnMgaW4gdGhlIGFycmF5IGlzOiAiIDw8IGV2ZW5Db3VudCA8PCBzdGQ6OmVuZGw7CiAgICAKICAgIHJldHVybiAwOwp9