-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathQ2.cpp
48 lines (43 loc) · 874 Bytes
/
Q2.cpp
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
40
41
42
43
44
45
46
47
48
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20], i, j, k, n;
clrscr();
printf("\nEnter array size: ");
scanf("%d", &n);
printf("\nEnter %d array element: ", n);
for(i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("\nOriginal array is: ");
for(i = 0; i < n; i++)
{
printf(" %d", a[i]);
}
printf("\nNew array is: ");
for(i = 0; i < n; i++)
{
for(j = i+1; j < n; )
{
if(a[j] == a[i])
{
for(k = j; k < n; k++)
{
a[k] = a[k+1];
}
n--;
}
else
{
j++;
}
}
}
for(i = 0; i < n; i++)
{
printf("%d ", a[i]);
}
getch();
}