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 <stdio.h>#define N 10int main(void) {    int i, values[N];    puts(Insert the values:);    for (i = 0; i < N; i++) {        scanf(%d, &values[i]);    }    /* Sorting */    int j, tmp, minvalue, minindex;    for (i = 0; i < N; i++) {        tmp = values[i];        minvalue = tmp;        for (j = i + 1; j < N; j++) {            if (values[j] < minvalue) {                minvalue = values[j];                minindex = j;            }        }        values[i] = minvalue;        values[minindex] = tmp;    }    printf(Array is: );    for (i = 0; i < N; i++) {        printf(%d , values[i]);    }    putchar('\n');    /* Actual counting */    int dupn = 0, duplicates[N], dupocc[N];    for (i = 0; i < N; i++) {        dupocc[i] = 0;    }    for (i = 1; i < N; i++) {        if (values[i] == values[i - 1]) {            duplicates[dupn] = values[i];            if (dupocc[dupn] == 0) dupocc[dupn]++;            dupocc[dupn]++;        } else if (dupocc[dupn] > 0) dupn++;    }    for (i = 0; i < dupn; i++) {        printf(Duplicate %d occurs %d times\n, duplicates[i], dupocc[i]);    }    return 0;}
Counting occurrences of duplicate items in an array
c;array
There are a few things that stand out to me immediately in your code. Some good, some are troubling.StyleFirst 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.SortingYour 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(Insert the values:);for (i = 0; i < N; i++) {    int val;    scanf(%d, &val);    int pos = i;    while (pos > 0 && values[pos - 1] > 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 < N; i++) {    if (values[i] != previous) {        // something changed... reset the counters        if (count > 1) {            // report the count of previous duplicates.            printf(Duplicate %d occurs %d times\n, previous, count);        }        previous = values[i];        count = 0;    }    count++;}if (count > 1) {    // catch the last count, if any    printf(Duplicate %d occurs %d times\n, previous, count);}