Thursday, 7 November 2013

C Program to delete duplicate elements in an array

#include <stdio.h>

#define SIZE 10

// change the value of size to increase the number of elements in array 

int main()
{
//declaring and initializing an array with 0's
int array[SIZE] = {0};
int backup[SIZE] = {0};
int I;
int J;
int count = 0;

printf("Enter %d integer values\n\n", SIZE);
for(I = 0; I<SIZE; I++)
{
printf("Integer %d : ", I+1);
scanf("%d", &array[I]);
}

for(I = 0; I < SIZE; I++)
{
for(J = 0; J < count; J++)
{
if(array[I] == backup[J])
break;
}
if(J == count)
{
backup[count] = array[I];
count++;
}
}

printf("Array after deleting duplicate elements\n");
for(I = 0; I < count; I++)
{
printf("%d\n", backup[I]);
}

   return 0;
}


Get Ebooks delivered to your email id

Comments

Subscribe to our channel

Facebook

Powered by Blogger.

Home | Contact Us | DMCA | Terms of Service | Privacy | Advertise

Maven Scientists