For your 'distinct' elements you need a int-Dictionary with key-type = int and value-type = int like C++/STL map<int,int>.
A simple ANSI C implementation for this map eg:
Code:
typedef struct {
int (*a)[2],i;
} IntDict;
int cmp(const void*a,const void *b) {
int i=*(int*)a,j=*(int*)b;
return (i>j)-(i<j);
}
void add(IntDict *a,int i) {
int x[2]={i},*p=bsearch(x,a->a,a->i,sizeof*a->a,cmp);
if( p )
p[1]++;
else
{
a->a=realloc(a->a,++a->i*sizeof*a->a);
memcpy(&a->a[a->i-1],x,sizeof x);
qsort(a->a,a->i,sizeof*a->a,cmp);
}
}
int main()
{
IntDict id={0};
/* insert all your values here, also duplicates... */
add(&id,3);add(&id,3);add(&id,3);add(&id,3);
add(&id,2);add(&id,2);add(&id,2);
add(&id,1);add(&id,1);
add(&id,0);
/* print out the dictionary with keys and values */
/* your distinct values are the dictionary-keys, here in [][0], values are occurrences in [][1] */
while( id.i-- )
printf("%5d %d\n",id.a[id.i][1]+1,id.a[id.i][0]),free(id.a[id.i]);
free(id.a);
return 0;
}