title: C - Counting the frequency of a number in an array
body: <p>I am trying to calculate the frequency of a value in an array. I thought I was on the right track with my current entry, but it seems to be miscounting the "count." I would love a second opinion on how to correctly show the frequency of the array! Here's what I have:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  /************************************************************************/
  /*                      Function: frequency                            */
  /*                                                                     */
  /*  Purpose:    Obtains the frequency of a number in an array          */
  /*                                                                     */
  /*                                                                     */ 
  /*                                                                     */
  /*  Parameters: theArray-The array in question                         */
  /*              n- the size of the array                               */
  /*              x- the number to search for frequency within the array */
  /*                                                                     */
  /*  Returns:    The frequency of a given number in an array              */
  /*                                                                     */
  /************************************************************************/
  
  int frequency (int theArray [ ], int n, int x)
  {
      int count = 0;
      int i;
  
      for (i = 0; i &lt; n; ++i)
      {
          if ( theArray[i]=x)
          {
              count = count + 1 ;
          }      
          else
          {
              count = count ;
          } 
      }
  
        printf ("\nThe frequency of %i in your array is %i ",x,count);
    }
  
    int main ()
    {
        int i;    
        int theArray[] = {};
        int n;
        int x;
  
  
        printf ("Enter The Amount Of Numbers In Your Array: ");
        scanf("%i", &amp;n);/*Stores Amound Of Numbers In The Array*/
  
        for (i = 0; i &lt; n; ++i)
        {
            printf("\nEnter number for array: ");     
            scanf ("%i", &amp;theArray[i]);
        }
  
        printf ("\nOK, Thanks! Now What Number Do You Want To Search For Frequency In Your Array? ");
        scanf("%i", &amp;x);/*Stores Number To Search For Frequency*/
  
        frequency(theArray,n,x);
  
        return(0);  /* success */
  
    } /* main */
  </code></pre>