Table of Contents
C program to find frequency of array element
We will create function which will return frequencies of elements
Logic to find frequency of array element in c
#include<stdio.h>
//itvoyagers.in
void feqfun(int a[],int len)
{
int i,j,temp,count=0;
for(i=0;i<len;i++)
{
if(a[i]!=(int)NULL)
{
temp=a[i];
for(j=0;j<len;j++)
{
if(temp==a[j])
{
count++;
a[j]=(int)NULL;
}
//itvoyagers.in
}
}
else
{
continue;
}
printf("nFrequency of %d is %d",temp,count);
count=0;
}
}
//itvoyagers.in
int main()
{
int nums[] = {1,2,5,4,5,2,1,5,2,2,4};
int l = sizeof(nums)/sizeof(float);
feqfun(nums,l);
}
//itvoyagers.in
Output :
Frequency of 1 is 2
Frequency of 2 is 4
Frequency of 5 is 3
Frequency of 4 is 2
PRACTICALS/PRACTICE PROGRAM IN C
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on Operator |
Easy Quiz on Operators in C part 1 |
Easy quiz on operators in C part 2 |
Easy quiz on operators in C part 3 |
Quizzes on Loops |
Easy quiz on loops in C part 1 |
Easy quiz on loops in C part 2 |
Easy quiz on loops in C part 3 |
Quizzes on Decision Making Statement |
Easy Quiz On Decision Making Statements Part 1 |
Easy Quiz On Decision Making Statements Part 2 |
Quizzes on String |
Easy quiz on String in C programming part 1 |
Quizzes on Array |
Easy quiz on Array in C programming – part 1 |
5 – Best Java program to convert decimal to binary |
New Quizzes Coming soon.. |
We are aiming to explain all concepts of C in easiest terms as possible.

ITVoyagers
Author