-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDQnew.c
More file actions
39 lines (36 loc) · 813 Bytes
/
Copy pathDQnew.c
File metadata and controls
39 lines (36 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<stdio.h>
int main()
{
//Taking input
int s = 0, f = 0;
printf("Input the array size: ");
scanf("%d", &s);
int a[s];
printf("Input an array: ");
for(int k = 0; k < s; k++) {
scanf("%d", &a[k]);
if(a[k] == 0)
f = 1;
}
//Removing the duplicates
int i = -1;
for(int k = 0; k < s; k++) {
if(a[k] == 0 & i == -1)
i = k;
for(int j = k+1; j < s; j++) {
if(a[k] == a[j]) {
a[j] = 0;
}
}
}
//Printing the new array
printf("\nThe new array is: ");
for(int k = 0; k < s; k++) {
if(a[k] != 0 && i != k)
printf("%d ", a[k]);
else if(i == k && f == 1)
printf("%d ", a[k]);
}
printf("\n");
return 0;
}