1.

Write a function to remove duplicates from an ordered array. For example, if input is: a,a,c,d,q,q,r,s,u,w,w,w,w; then the output should be a,c,d,q,r,s,u,w. 

Answer»

A C program to remove duplicates from an odered array:

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

int i,j,k,l,flag=0;

char a[50];

clrscr();

printf("enter the characters in the array");

gets(a);

l=strlen(a);

for(i=0;i<l-1;i++)

 for(j=i+1;j<l;j++)

{

 if(a[i]==a[j])

 { l=l-1;

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

 a[k]=a[k+1];

 flag=1;

 j=j-1;

 }

}

if(flag==0)

 printf("No duplicates found");

else

 for(i=0;i<l;i++)

printf("%c",a[i]);

getch();

}



Discussion

No Comment Found

Related InterviewSolutions