Write a C program to read and print containts OF AN ARRAY FIND FREQUENCY OF EACH VALUE WITHIN AN ARRAY.

#include<stido.h>

int main(){

int MAX =20;
int arr[20] = {1,2,30,4,1,2,6,8,5,0,9,8,3,5,6,7,2,6,1,1};
int frequency[2][20];
int counter = 0;
int flag = 0;
int i =0,j=0,k=0;
int pivot;

for (i=0;i<MAX;i++){
pivot = arr[i];

for (k=0;k<j;k++){

if (pivot == frequency[0][k]){

flag = 1;
break;
}
}

if (flag == 0){

for(k=0;k<MAX;k++){

if(pivot ==arr[k])
counter++;

}

frequency[0][j] = pivot;
frequency[1][j] = counter;
counter = 0;
j++;

}

flag= 0;

}

for(i=0;i<j;i++){

printf("Element : %d, Frequency : %d \n",frequency[0][i],frequency[1][i]);

}

return 0;

}

0 comments:

Feel free to contact the admin for any suggestions and help.