fork download
  1. #include <stdio.h>
  2.  
  3.  
  4.  
  5. // Function prototype
  6.  
  7. // counts the number of times x appears among the first n elements of the array
  8. int frequency (int theArray [ ], int n, int x);
  9.  
  10.  
  11. int main(void) {
  12.  
  13. int myArray[] = {5, 7, 23, 8, 23, 67, 23};
  14.  
  15. printf("Number of times %i appears in first %i elements = %i\n\n", 23, 7, frequency(myArray, 7, 23));
  16.  
  17.  
  18. return 0;
  19. }
  20.  
  21.  
  22.  
  23.  
  24. //**************************************************************/
  25. // Function: frequency
  26. //
  27. // Purpose: Calculate and return the number of times x appears in first n elements of the given array
  28. //
  29. // Parameters:
  30. // theArray - array of integers
  31. // n - the first n elements in the array
  32. // x - the number to check for
  33. // side4 - Length of side 4
  34. //
  35. // Returns: the number of times x appears in first n elements of the given array
  36. //
  37. //**************************************************************/
  38.  
  39. int frequency (int theArray [ ], int n, int x)
  40. {
  41. int i; // loop counter
  42.  
  43.  
  44.  
  45. for (i = 0; i < n; i++)
  46. {
  47. if (x == theArray[i])
  48. {
  49. count++;
  50. }
  51.  
  52. }
  53.  
  54. return count;
  55.  
  56. }
  57.  
  58.  
Compilation error #stdin compilation error #stdout 0s 9416KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘frequency’:
prog.c:49:4: error: ‘count’ undeclared (first use in this function)
    count++;
    ^~~~~
prog.c:49:4: note: each undeclared identifier is reported only once for each function it appears in
prog.c:56:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty