Find the frequencies of the array elements.
C++
/*Write a C++ program to input elements in array
and find frequency of each element in array.*/
#include<iostream>
using namespace std;
void FindFrequency(int *arr,int size)
{
int i,j=0;
int frequency[size];
for(i=0;i<size;i++)
{
int freq=0;
for(j=0;j<size;j++)
{
if(arr[i]==arr[j])
{
freq++;
}
}
cout<<"Frequency of "<<arr[i]<<" = "<<freq<<endl;
}
}
int main()
{
int size;
// cout<<"Input the size of the array : ";
cin>>size;
int position;
int arr[size];
// cout<<"Input the array elements : ";
for(int i=0;i<size;i++)
{
cin>>arr[i];
}
FindFrequency(arr,size);
return 0;
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.