#include <stdio.h>
// Function prototype
// counts the number of times x appears among the first n elements of the array
int frequency ( int theArray [ ] , int n, int x) ;
int main( void ) {
int myArray[ ] = { 5 , 7 , 23 , 8 , 23 , 67 , 23 } ;
printf ( "Number of times %i appears in first %i elements = %i\n \n " , 23 , 7 , frequency
( myArray
, 7 , 23 ) ) ;
return 0 ;
}
//**************************************************************/
// Function: frequency
//
// Purpose: Calculate and return the number of times x appears in first n elements of the given array
//
// Parameters:
// theArray - array of integers
// n - the first n elements in the array
// x - the number to check for
// side4 - Length of side 4
//
// Returns: the number of times x appears in first n elements of the given array
//
//**************************************************************/
int frequency ( int theArray [ ] , int n, int x)
{
int i; // loop counter
for ( i = 0 ; i < n; i++ )
{
if ( x == theArray[ i] )
{
count++;
}
}
return count;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgoKCi8vIEZ1bmN0aW9uIHByb3RvdHlwZQoKLy8gY291bnRzIHRoZSBudW1iZXIgb2YgdGltZXMgeCBhcHBlYXJzIGFtb25nIHRoZSBmaXJzdCBuIGVsZW1lbnRzIG9mIHRoZSBhcnJheQppbnQgZnJlcXVlbmN5IChpbnQgdGhlQXJyYXkgWyBdLCBpbnQgbiwgaW50IHgpOyAKCiAKaW50IG1haW4odm9pZCkgewoJCglpbnQgbXlBcnJheVtdID0gezUsIDcsIDIzLCA4LCAyMywgNjcsIDIzfTsKIAoJcHJpbnRmKCJOdW1iZXIgb2YgdGltZXMgJWkgYXBwZWFycyBpbiBmaXJzdCAlaSBlbGVtZW50cyA9ICVpXG5cbiIsIDIzLCA3LCBmcmVxdWVuY3kobXlBcnJheSwgNywgMjMpKTsKIAogCglyZXR1cm4gMDsKfQogCiAKIAoKLy8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KLy8gRnVuY3Rpb246IGZyZXF1ZW5jeQovLyAKLy8gUHVycG9zZTogQ2FsY3VsYXRlIGFuZCByZXR1cm4gdGhlIG51bWJlciBvZ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