fork download
  1. #include <stdio.h>
  2.  
  3. int somarpar(int vet[], int n) {
  4. return n > 0 ? somarpar(vet, n - 1) + (vet[n] % 2 == 0 ? vet[n] : 0) : 0;
  5. }
  6.  
  7. int main(void) {
  8. int vetor[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  9. printf("a soma dos numeros pares eh: %i\n", somarpar(vetor, 10));
  10. }
  11.  
  12. //https://pt.stackoverflow.com/q/246494/101
Success #stdin #stdout 0s 10320KB
stdin
Standard input is empty
stdout
a soma dos numeros pares eh: 30