fork download
  1. #include <stdio.h>
  2.  
  3. int oddsum(int data[], int n) {
  4. int total = data[0];
  5. int i;
  6.  
  7.  
  8.  
  9. for (i = 0; i <= n; i++)
  10. if ((data[i] % 2) == 1) {
  11.  
  12. total += data[i];
  13. return total;
  14. }
  15.  
  16. }
  17. #define N 5
  18. int main(void)
  19. {
  20. int data[N] = { 1,3,5,7,11 };
  21.  
  22. printf("data=1,3,5,7,11\n");
  23. printf("oddsum=%d\n", oddsum(data, N));
  24.  
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
data=1,3,5,7,11
oddsum=2