Here is the source code of the C program to find the number of occurrences of a given number in a list. The C Program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to find the number of occurences of a given number in a
void occur(int , int, int, int, int *);
int size, key, count = 0;
printf("Enter the size of the list: ");
printf("Printing the list:\n");
for (i = 0; i < size; i++)
list[i] = rand() % size;
printf("%d ", list[i]);
printf("\nEnter the key to find it's occurence: ");
occur(list, size, 0, key, &count);
printf("%d occurs for %d times.\n", key, count);
void occur(int list, int size, int index, int key, int *count)
if (size == index)
if (list[index] == key)
*count += 1;
occur(list, size, index + 1, key, count);
$ cc pgm13.c $ a.out Enter the size of the list: 7 Printing the list: 1 4 2 5 1 3 3 Enter the key to find it's occurence: 3 3 occurs for 2 times.
Sanfoundry Global Education & Learning Series – 1000 C Programs.