#include <stdio.h>

// Function prototype
int frequency(int theArray[], int n, int x);

// Function definition
/**
 * Function Name: frequency
 * 
 * Function Block:
 * Counts the number of times the item x appears among the first n elements of theArray.
 * 
 * @param theArray[] The array of integers to search within.
 * @param n The number of elements in the array to consider.
 * @param x The integer value to count within the array.
 * @return The frequency of x in the first n elements of theArray.
 */
int frequency(int theArray[], int n, int x) {
    int count = 0; // Initialize count to 0

    // Loop through the first n elements of the array
    for (int i = 0; i < n; i++) {
        if (theArray[i] == x) {
            count++; // Increment count if the element matches x
        }
    }

    return count; // Return the final count
}

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

    // Call the frequency function and print the result
    int result = frequency(theArray, n, x);
    printf("The frequency of %d in the first %d elements is: %d\n", x, n, result);

    return 0;
}