// Input an integer array a of size 15 from the user. The array can have multiple // occurrences of elements. You have to remove the multiple occurences of elements // and store the distinct elements in a new array along with their count. The // memory for the new array has to be dynamically allocated using malloc such that // its size is twice the number of distinct elements in A. //Author:rahule@iitk.ac.in #include #include int not_in(int *,int,int); int count(int item,int *a); int find_distict(int a[15]); main() { int a[15],i,j,cnt=6,*new_a,t; printf("\nEnter the numbers :\n"); for(i=0;i<15;i++) scanf("%d",&a[i]); //STEP 1:Finding number distinct elements in the array cnt=find_distict(a); //finds number of distict elements in the array a new_a=(int *)malloc(2*cnt*sizeof(int)); //creates 2*cnt space t=0;i=1; for(i=0;i<15;i++) { if(not_in(new_a,2*cnt,a[i])) //if a[i] NOT IN new_a { new_a[t]=a[i]; //then ass a[i] to new_a togather with its count new_a[t+1]=count(a[i],a); t=t+2; } } printf("The distict elements with its count are as follows\n"); for(i=0;i<2*cnt;i++) printf("%d ",new_a[i]); printf("\n"); } int not_in(int *a,int cnt,int item) //function to check whether 'item' is among "cnt" number of elements in the array { int i; for(i=0;i