1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#include <stdio.h> int main() { int arr[100], frequency[100]; int i, j, count, num; //Enter size of array printf("Enter size of array: "); scanf("%d", &num); //Reading elements of array printf("Enter elements in array: "); for(i=0; i<num; i++) { scanf("%d", &arr[i]); //Initially initialize frequency variable to -1 frequency[i] = -1; } for(i=0; i<num; i++) { count = 1; for(j=i+1; j<num; j++) { //If duplicate element is found if(arr[i]==arr[j]) { count++; //Make sure not to count frequency of same element again frequency[j] = 0; } } //If frequency of current element is not counted if(frequency[i] != 0) { frequency[i] = count; } } //Print frequency of each element printf("\nFrequency of all elements of array : \n"); for(i=0; i<num; i++) { if(frequency[i] != 0) { printf("%d occurs %d times\n", arr[i], frequency[i]); } } return 0; } |
04 December 2019 1461 Written By: Rohit
© 2020 Tech Study. All rights reserved | Developed by Tech Study| Privacy Policy | Sitemap