This is a 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.
Prints the repeated numbers with frequency in a given array as shown in the program below.
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.
/* * C Program to Print all the Repeated Numbers with Frequency in an Array */ #include <stdio.h> #include <malloc.h> void duplicate(int array[], int num) { int *count = (int *)calloc(sizeof(int), (num - 2)); int i; printf("duplicate elements present in the given array are "); for (i = 0; i < num; i++) { if (count[array[i]] == 1) printf(" %d ", array[i]); else count[array[i]]++; } } int main() { int array[] = {5, 10, 10, 2, 1, 4, 2}; int array_freq = sizeof(array) / sizeof(array[0]); duplicate(array, array_freq); getchar(); return 0; }
In this C Program, we have defined the array[] variable elements. Compute the division of size of previous array value by the next array[] variable element value. the duplicate() function is used to find the repeated numbers with frequency in an array.
In duplicate() function using for loop find the duplicate numbers present in the given array. If else condition statement is used to check that count[] array variable with base index value of array[] variable is equal to 1.
If the condition is true, then execute the statement and print the duplicate elements in the array. Otherwise, if the condition is false, then execute the else statement and increment the count variable value.
$ 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 Books in C Programming, Data-Structures and Algorithms
- Check C Books
- Apply for Computer Science Internship
- Apply for C Internship
- Practice Computer Science MCQs
- Check Computer Science Books