fork download
  1. #include <fstream>
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. long calc(long nums[], int index)
  7. {
  8. if (index == -1)
  9. {
  10. return 0;
  11. }
  12. return (nums[index] % 2 == 0)
  13. ? nums[index] + calc(nums, index - 1)
  14. : calc(nums, index - 1);
  15. }
  16.  
  17. int main()
  18. {
  19. // freopen("b8.txt", "r", stdin);
  20.  
  21. int n;
  22. cin >> n;
  23. long nums[n];
  24. for (int i = 0; i < n; i++)
  25. {
  26. cin >> nums[i];
  27. }
  28.  
  29. cout << calc(nums, n - 1) << endl;
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5300KB
stdin
5
11 37 70 90 53
stdout
160