Write a program to count frequency of specific element in an array.
- #include <stdio.h>
- void main()
- {
- int arr[100], freq[100];
- int n, i, j, count;
- printf("Input the number of elements to be stored in the array :");
- scanf("%d", &n);
- printf("Input %d elements in the array :\n", n);
- for(i=0; i<n; i++) {
- printf("Element - %d : ",i);
- scanf("%d", &arr[i]);
- freq[i] = -1;
- }
- for(i=0; i<n; i++) {
- count = 1;
- for(j=i+1; j<n; j++) {
- if(arr[i] == arr[j]) {
- count++;
- freq[j] = 0;
- }
- }
- if(freq[i] != 0) {
- freq[i] = count;
- }
- }
- printf("\nThe frequency of all elements of array : \n");
- for(i=0; i<n; i++) {
- if(freq[i]!=0) {
- printf("%d occurs %d times\n", arr[i], freq[i]);
- }
- }
- }
একটি মন্তব্য পোস্ট করুন