

 // ***************************************************
 // Function: frequency
 //
 // Description: Counts the number of times a specific
 //              integer appears in an array.
 //
 // Parameters: theArray - array of integers
 //             n        - number of elements to check
 //             x        - integer to search for
 //
 // Returns:    count - number of times x appears
 //                     in the first n elements
 //
 // ***************************************************

int frequency(int theArray[], int n, int x)
{
    int count = 0; // Initialize counter to zero
    int i;         // Loop index variable

    // Loop through the first n elements of the array
    for (i = 0; i < n; i++)
    {
        // Check if the current element matches x
        if (theArray[i] == x)
        {
            count++; // Increase count when a match is found
        }
    }

    // Return the total number of times x was found
    return count;

} // frequency


#include <stdio.h>

int main(void)
{
    int theArray[] = {5, 7, 23, 8, 23, 67, 23};
    int n = 7;
    int x = 23;

    printf("Frequency of %d is %d\n",
           x, frequency(theArray, n, x));

    return 0;
}

