fork download
  1. #include <stdio.h>
  2.  
  3. int frequency(int theArray[], int n, int x)
  4. {
  5. int count = 0;
  6. for (int i = 0; i < n; i++) {
  7. if (theArray[i] == x) {
  8. count++;
  9. }
  10. }
  11. return count;
  12. }
  13.  
  14. int main() {
  15. int theArray[] = {5, 7, 23, 8, 23, 67, 23};
  16. int n = 7;
  17. int x = 23;
  18. printf("Frequency of %d in the array: %d\n", x, frequency(theArray, n, x));
  19. return 0;
  20. }
  21.  
  22.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Frequency of 23 in the array: 3