WAP which deletes the duplicate element of an array?
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[20], i, j, k, s;
printf("\nEnter array size : ");
scanf("%d", &s);
printf("\nAccept Numbers : ");
for (i = 0; i < s; i++)
scanf("%d", &arr[i]);
printf("\nArray with Unique list : ");
for (i = 0; i < s; i++)
{
for (j = i + 1; j < s;)
{
if (arr[j] == arr[i])
{
for (k = j; k < s; k++)
{
arr[k] = arr[k + 1];
}
s--;
}
else
j++;
}
}
for (i = 0; i < s; i++)
{
printf("%d ", arr[i]);
}
return (0);
}
Enter array size : 5
Accept Numbers : 1 3 4 5 3
Array with Unique list : 1 3 4 5
No comments:
Post a Comment