fork download
  1. #include <iostream>
  2.  
  3. int countEvenRecursive(int arr[], int size, int index) {
  4. if (index == size) {
  5. return 0;
  6. }
  7.  
  8. if (arr[index] % 2 == 0) {
  9. return 1 + countEvenRecursive(arr, size, index + 1);
  10. } else {
  11. return countEvenRecursive(arr, size, index + 1);
  12. }
  13. }
  14.  
  15. int main() {
  16. int a[] = {1, 4, 6, 3, 7, 11, 8, 9, 10};
  17. int size = sizeof(a) / sizeof(a[0]);
  18.  
  19. int evenCount = countEvenRecursive(a, size, 0);
  20.  
  21. std::cout << "The number of even values in the array is: " << evenCount << std::endl;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
The number of even values in the array is: 4