Input some elements in an array and remove the duplicate element.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int arr[10], i, j, f, temp[10], k = 0;
clrscr ( );
for ( i = 0; i < 10; i++ )
{
printf("\n\t\t\t Enter a number..:"); scanf("%d",&arr[i]);
}
printf("\n\n\t After removing duplicate elements.:");
for ( i = 0; i < 10; i++ )
{
f = 0;
for ( j = 0; j < i; j++ )
{
if ( arr[j] == arr[i] )
{
f = 1;
}
}
if ( f == 0 )
temp[k++] = arr[i];
}
for ( i = 0; i < k; i++ )
{
arr[i] = temp [i];
}
for ( i = 0; i < k; i++ )
{
printf("%d,",arr[i]);
}
getch ( );
}
Click here to contact us
No comments:
Post a Comment