#include<stdio.h>
int main()
{
int arrIn[20], arrOut[20];
int i, j, k, size, temp,cnt=0, flag=0;
printf("\nEnter array size(Max 20) : ");
scanf("%d", &size);
printf("\nEnter %d Numbers : ", size);
for (i = 0; i < size; i++)
scanf("%d", &arrIn[i]);
printf("\nYour array elements:");
for (i = 0; i < size; i++)
printf("%d ", arrIn[i]);
//Logic to delete duplicate array elements
for (i=0; i < size; i++)
{
temp = arrIn[i];
flag = 0;
for (j=i+1; j<size; j++)
{
if (arrIn[j] == temp )
{
flag=1; cnt++;
break;
}
else
flag=0;
}
if(flag==0)
arrOut[k++]=temp;
}
printf("\n\nArray with unique elements:\n");
for (i=0; i<size-cnt; i++)
{
printf("%d ", arrOut[i]);
}
return (0);
}
Output of program
Enter array size(Max 20) : 10
Enter 10 Numbers : 1 2 2 3 3 4 5 5 6 7
Your array elements:1 2 2 3 3 4 5 5 6 7
Array with unique elements:
1 2 3 4 5 6 7
int main()
{
int arrIn[20], arrOut[20];
int i, j, k, size, temp,cnt=0, flag=0;
printf("\nEnter array size(Max 20) : ");
scanf("%d", &size);
printf("\nEnter %d Numbers : ", size);
for (i = 0; i < size; i++)
scanf("%d", &arrIn[i]);
printf("\nYour array elements:");
for (i = 0; i < size; i++)
printf("%d ", arrIn[i]);
//Logic to delete duplicate array elements
for (i=0; i < size; i++)
{
temp = arrIn[i];
flag = 0;
for (j=i+1; j<size; j++)
{
if (arrIn[j] == temp )
{
flag=1; cnt++;
break;
}
else
flag=0;
}
if(flag==0)
arrOut[k++]=temp;
}
printf("\n\nArray with unique elements:\n");
for (i=0; i<size-cnt; i++)
{
printf("%d ", arrOut[i]);
}
return (0);
}
Output of program
Enter array size(Max 20) : 10
Enter 10 Numbers : 1 2 2 3 3 4 5 5 6 7
Your array elements:1 2 2 3 3 4 5 5 6 7
Array with unique elements:
1 2 3 4 5 6 7
No comments:
Post a Comment