Tuesday 4 September 2012

Array023

Input some elements in the array and remove the duplicate elements from that array.

#include <stdio.h>
#include <conio.h>
void main ( )
{
           int        arr[10], dup[10], i, j, k = 0, f;
           clrscr ( );
           for( i = 0; i < 10; i++ )
           {                                          
                          printf("\n\t\t\t Enter a number..:");    scanf("%d",&arr[i]);
           }
             
           for ( i = 0; i < 10; i++)
           {                                  
                           f = 0;
                           for ( j = 0; j < i; j++ )
                           {                                
                                           if ( arr[i] == arr[j] )
                                           {                            
                                                           f = 1;
                                                           break;
                                           }
                           }
                           if ( f == 0 )
                           dup[k++] = arr[i];
           }               
           for ( i = 0; i < k; i++ )
           {                                  
                           arr[i] = dup[i];
           }                  
          
           printf("\n Removing the duplicate elements the array becomes..:");
           for ( i = 0; i < k; i++ )
           {                                   
                           printf("%d,",arr[i] );
           }
           getch ( );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...