Tuesday 24 June 2014

C++ program to remove duplicates of a character in a string


Here is a C++ program to remove duplicates of a character in a string


 SOURCE CODE OUTPUT
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
    char str[100];
    int n=1;
    cout<<"Enter string : ";
    cin>>str;
    for(int i=0;str[i]!='\0';i++)
    {
        for(int y=i+1;str[y]!='\0';y++)
            if(str[i]==str[y]||str[i]==char(str[y]+32)||str[i]==char(str[y]-32))
                str[y]=' ';
    }
    cout<<"After removing duplicate characters : "<<str;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment