C Code 36 _ To Remove the repeating characters from the given string


C Code 36 _ To Remove the repeating characters from the given string 


Sample Input:

Hello

Sample Output:

Helo


Program:


#include<stdio.h>
#include<string.h>
int present(char c,int m);
char str[200],ans[200];

int present(char c,int m)
{
                int v=0;
                int k;
                for(k=0;k<m;k++)
                {
                                if(c==ans[k])
                                {
                                                v=1;
                                                break;
                                }
                }
                if(v==1)
                {
                                return 1;
                }
                else
                {
                                return 0;
                }
}


int main()
{
                int i,len,j=0,p,k;
                printf("\nEnter a String : ");
                scanf("%s",str);
                len=strlen(str);
                printf("Length of original string : %d",len);
                for(i=0;i<len;i++)
                {
                                p=present(str[i],j);
                                if(!p)
                                {
                                                ans[j]=str[i];
                                                j=j+1;
                                }
                }
                printf("\n\nFinal String : %s",ans);
                printf("\nLength of Final String : %d",strlen(ans));
                return 0;
}


Output: 









Thank You ...



Previous Post
Next Post
Related Posts

0 comments:

Popular Posts