C Program to Print all the Repeated Numbers with Frequency in an Array

This C Program print all the repeated numbers with frequency in an array.

Here is source code of the C Program to print all the repeated numbers with frequency in an array. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C Program to Print all the Repeated Numbers with Frequency in an Array
  3.  */
  4. #include <stdio.h>
  5. #include <malloc.h>
  6.  
  7. void duplicate(int array[], int num)
  8. {
  9.     int *count = (int *)calloc(sizeof(int), (num - 2));
  10.     int i;
  11.  
  12.     printf("duplicate elements present in the given array are ");
  13.     for (i = 0; i < num; i++)
  14.     {
  15.         if (count[array[i]] == 1)
  16.             printf(" %d ", array[i]);
  17.         else
  18.             count[array[i]]++;
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     int array[] = {5, 10, 10, 2, 1, 4, 2};
  25.     int array_freq = sizeof(array) / sizeof(array[0]);
  26.     duplicate(array, array_freq);
  27.     getchar();
  28.     return 0;
  29. }

$ cc pgm71.c
$ a.out
 duplicate elements present in the given array are  10  2

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Arrays, go to C Programming Examples on Arrays. If you wish to look at programming examples on all topics, go to C Programming Examples.
Subscribe Newsletter & Posts
About

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.


Sanfoundry Training Center of Excellence (CoE)

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.


Follow Manish & Sanfoundry