Counting occurrences of duplicate items in an array I have to make a simple program that reads N integers from the user and counts the occurrences of duplicate items. I know that the chosen sorting algorithm has poor performance, but I chose it for its simplicity.

I'm looking for suggestions for the last part, in which I count the duplicates.

#include &lt;stdio.h&gt;

#define N 10


int main(void) {
    int i, values[N];
    puts("Insert the values:");
    for (i = 0; i &lt; N; i++) {
        scanf("%d", &amp;values[i]);
    }

    /* Sorting */
    int j, tmp, minvalue, minindex;
    for (i = 0; i &lt; N; i++) {
        tmp = values[i];
        minvalue = tmp;
        for (j = i + 1; j &lt; N; j++) {
            if (values[j] &lt; minvalue) {
                minvalue = values[j];
                minindex = j;
            }
        }
        values[i] = minvalue;
        values[minindex] = tmp;
    }

    printf("Array is: ");
    for (i = 0; i &lt; N; i++) {
        printf("%d ", values[i]);
    }
    putchar('\n');

    /* Actual counting */
    int dupn = 0, duplicates[N], dupocc[N];
    for (i = 0; i &lt; N; i++) {
        dupocc[i] = 0;
    }
    for (i = 1; i &lt; N; i++) {
        if (values[i] == values[i - 1]) {
            duplicates[dupn] = values[i];
            if (dupocc[dupn] == 0) dupocc[dupn]++;
            dupocc[dupn]++;
        } else if (dupocc[dupn] &gt; 0) dupn++;
    }
    for (i = 0; i &lt; dupn; i++) {
        printf("Duplicate %d occurs %d times\n", duplicates[i], dupocc[i]);
    }
    return 0;
}
There are a few things that stand out to me immediately in your code. Some good, some are troubling.
Style
First up, your code is neat, and well structured. Indentation is good, and I even appreciate the fact that you have braced 1-liners and got the space right in your expressions.
Traditionally, C puts the open brace on the new line.... I am not a fan of that, but I don't write C very often, so I stick with a style I use in Java. Just thought I would point that out, though.
Sorting
Your sort algorithm is ... basic, but effective. I would agree that it is a problem. As a suggestion, you should use an insertion sort, and do the sort at the same time as the scanf. That way you load the data in an always-sorted way:
puts(&quot;Insert the values:&quot;);
for (i = 0; i &lt; N; i++) {
    int val;
    scanf(&quot;%d&quot;, &amp;val);
    int pos = i;
    while (pos &gt; 0 &amp;&amp; values[pos - 1] &gt; val) {
        values[pos] = values[pos - 1];
        pos--;
    }
    values[pos] = val;
}

The above will do a shifting insertion sort. Just a suggestion.
Duplicates.
This is where there are the most significant problems. I would consider your algorithm to be a real overkill one. You can do it all with no extra data, no duplicates[] array, etc. A simple loop through the data should be fine.
int count = 1;
int previous = values[0] + 1; // something different to the start.
for (int i = 0; i &lt; N; i++) {
    if (values[i] != previous) {
        // something changed... reset the counters
        if (count &gt; 1) {
            // report the count of previous duplicates.
            printf(&quot;Duplicate %d occurs %d times\n&quot;, previous, count);
        }
        previous = values[i];
        count = 0;
    }
    count++;
}
if (count &gt; 1) {
    // catch the last count, if any
    printf(&quot;Duplicate %d occurs %d times\n&quot;, previous, count);
}