fork download
  1. #include <stdio.h>
  2.  
  3. struct t { int hasColided; }
  4. table[] = {
  5. { .hasColided = 0 },
  6. { .hasColided = 1 },
  7. { .hasColided = 1 },
  8. { .hasColided = 1 },
  9. { .hasColided = 1 },
  10. { .hasColided = 0 },
  11. { .hasColided = 1 } };
  12. int size = 7;
  13.  
  14. int getNumPastasColididas(int i, int c) {
  15. return (i < size) ? table[i].hasColided + getNumPastasColididas(i + 1, c) : c;
  16. }
  17.  
  18. int main(void) {
  19. printf("%d", getNumPastasColididas(0, 0));
  20. }
  21.  
  22. //https://pt.stackoverflow.com/q/138497/101
  23.  
Success #stdin #stdout 0s 4520KB
stdin
Standard input is empty
stdout
5