Occurrence

Description:

There was a group of elements in which there may be repeated elements. So there was a task to find occurrence of an element in one dimensional array. Write a C program for this scenario Test Case 1 Input (stdin) 6 10 20 30 10 50 60 10 Expected Output 2 Test Case 2 Input (stdin) 3 1 2 3 3 Expected Output 1

Program :

#include <stdio.h>

#define MAX 100

int main()

{

    int arr[MAX],n,i;

    int num,count;

    scanf("%d",&n);

    for(i=0;i< n;i++)

    {

        scanf("%d",&arr[i]);

    }

    scanf("%d",&num);

    count=0;

    for(i=0;i< n;i++)

    {

        if(arr[i]==num)

            count++;

    }

    printf("%d",count);

    return 0;

}