By which I mean this:
Given the input set of numbers:
1,2,3,4,5 becomes \"1-5\".
1,2,3,5,7,9,10,11,12,14 becomes \"1-3, 5, 7, 9-12, 14\"
This is
See How would you display an array of integers as a set of ranges? (algorithm)
My answer to the above question:
void ranges(int n; int a[n], int n)
{
qsort(a, n, sizeof(*a), intcmp);
for (int i = 0; i < n; ++i) {
const int start = i;
while(i < n-1 and a[i] >= a[i+1]-1)
++i;
printf("%d", a[start]);
if (a[start] != a[i])
printf("-%d", a[i]);
if (i < n-1)
printf(",");
}
printf("\n");
}