top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

FInd out number of occurrences of a number in an array using C

+1 vote
272 views

In a class they will give some set of students height and we need to calculate number of occurrence of the particular height;

EG::: input(54,55,40,48,54,54)
if they give 54 your program should return 3
if they give 40 your program should return 1
if they give 60 your program should return 0

posted Aug 28, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

What you need is the array, size of the array and the value to be searched. Just run the loop from zero to end and count if numer exists....

Sample function

int count_occur(int a[], char exists[], int num_elements, int value)
{
    int i, count = 0;

    for (i = 0; i < num_elements; i++)
    {
        if (a[i] == value)
        {
            if (exists[i] != 0) return 0;
            ++count; /* it was found */
        }
    }
    return (count);
}
answer Aug 28, 2017 by Salil Agrawal
Similar Questions
+1 vote

Given an array of integers (possibly some of the elements negative), write a C program to find out the *maximum product* possible by adding 'n' consecutive integers in the array, n <= ARRAY_SIZE.

Also give where in the array this sequence of n integers starts.

+1 vote

Given an array of 1s and 0s which has all 1s first followed by all 0s. Find the number of 0s. Count the number of zeroes in the given array.

...