fork download
  1. /*count the occurrences of a value in an array */
  2.  
  3. #include <stdio.h>
  4.  
  5.  
  6. int main(void)
  7. {
  8. int myarray[] = {4,9,7,6,5,8,3,2,1,5};
  9. int count = 0;
  10. int to_find = 5;
  11.  
  12. for (int i = 0; i < 10; i++){
  13. if (myarray[i] == to_find) count++;
  14. }
  15.  
  16. printf("# of 5s found: %d\n", count);
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
stdout
# of 5s found: 2