Count the number of times a number appears in an array

前端 未结 6 1337
我在风中等你
我在风中等你 2021-01-20 15:48

I\'m working on a small program that counts the number of times an integer appears in an array. I managed to do this but there is one thing I can\'t overcome.

My cod

6条回答
  •  长发绾君心
    2021-01-20 16:27

    In your function :

    int count_occur(int a[], int num_elements, int value)
    /* checks array a for number of occurrances of value */
    {
      int i, count = 0;
      for (i = 0; i

    And in main() you can edit for loop:

    for (i = 0; i<20; i++)
      {
         if(a[i] != INFINITY)
         {
             num_occ = count_occur(a, 20, a[i]);
             printf("The value %d was found %d times.\n", a[i], num_occ);
         }
      }
    

提交回复
热议问题