Removing duplicate items from a sorted array
#include <stdio.h>
#include <stdlib.h>
int main() {
int arr[12] = { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5 };
int temp[12];
int i, j, k, n = 12;
for (i = 0; i < n - 1; i++) {
if (arr[i] != arr[i + 1]) {
temp[j] = arr[i];
j++;
}
}
temp[j] = arr[n - 1];
for (k = 0; k <= j; k++) {
printf("%d\n", temp[k]);
}
return 0;
}
Output:
6356652
1955753237
1956070172
6356716
1955750536
8
1955687363
1955687354
1
2
3
4
5
Process returned 0 (0x0) execution time : 0.014 s
Press any key to continue.
I do not want these numbers to be printed out:
6356652
1955753237
1956070172
6356716
1955750536
8
1955687363
1955687354
jortemp[12]