Remove duplicate elements from keyboard: C Program

0
2040

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.

[nextpage title=”Program” ]

[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]

[/nextpage]

[nextpage title=”Output” ]

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

How many elements ?

10

Enter 10  elements (with some duplication)

10 20 10 40 50 20 30 60 70

After removing duplicate elements

10

20

30

40

50

60

70

[/message_box]
[/nextpage]

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

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

[/message_box]