Remove duplicate elements from keyboard: C Program

0
22

This C program remove same elements from given list.

This program visit each numbers if number is visited again then remove that number.For example  given array= 1, 2, 1, 3, 4, 2, 5, 4. After removing duplicate elements from the given array we get elements=1, 2, 3, 4, 5.

[message_box title=”PROGRAM” color=”yellow”]

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

#include <stdio.h>

#include <conio.h>

void main()

{

int m[10], i, k=0, j, n,store[10], flag;

clrscr();

printf(“How many elements ?”);

scanf (“%d”, &n);

printf ( ” Enter %d  elements (with some duplication) \n “,n );

for( i=o;i<n; ++i)

{

scanf ( “%d “,&m[i] );

flag=0;

for(j=0; j<k ; ++j)

{

if ( m[i]==store[j] )

{

flag=1;

break;

}

}

if(flag==0)

{

store[k]=m[i];

k++;

}

}

printf (“After removing duplicate elements \n”);

for(j=0; j<k ; ++j)

{

printf (” %d \n”,store[j] );

}

}

[/message_box]

[message_box title=”NOTE” color=”green”]

NOTE :- You can also run this program without using second array.

[/message_box]

 [/sociallocker-bulk-1]

Leave a Reply

Be the First to Comment!

Notify of
wpDiscuz