File tree 1 file changed +59
-0
lines changed 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+
3
+ #define MAX_SIZE 100 // Maximum size of the array
4
+
5
+ int main ()
6
+ {
7
+ int arr [MAX_SIZE ]; // Declares an array of size 100
8
+ int size ; // Total number of elements in array
9
+ int i , j , k ; // Loop control variables
10
+
11
+ /* Input size of the array */
12
+
13
+ scanf ("%d" , & size );
14
+
15
+ /* Input elements in the array */
16
+
17
+ for (i = 0 ; i < size ; i ++ )
18
+ {
19
+ scanf ("%d" , & arr [i ]);
20
+ }
21
+
22
+
23
+ /*
24
+ * Find duplicate elements in array
25
+ */
26
+ for (i = 0 ; i < size ; i ++ )
27
+ {
28
+ for (j = i + 1 ; j < size ; j ++ )
29
+ {
30
+ /* If any duplicate found */
31
+ if (arr [i ] == arr [j ])
32
+ {
33
+ /* Delete the current duplicate element */
34
+ for (k = j ; k < size ; k ++ )
35
+ {
36
+ arr [k ] = arr [k + 1 ];
37
+ }
38
+
39
+ /* Decrement size after removing duplicate element */
40
+ size -- ;
41
+
42
+ /* If shifting of elements occur then don't increment j */
43
+ j -- ;
44
+ }
45
+ }
46
+ }
47
+
48
+
49
+ /*
50
+ * Print array after deleting duplicate elements
51
+ */
52
+
53
+ for (i = 0 ; i < size ; i ++ )
54
+ {
55
+ printf ("%d\t" , arr [i ]);
56
+ }
57
+
58
+ return 0 ;
59
+ }
You can’t perform that action at this time.
0 commit comments