Returns First Repeating Character from Array

This program is to Returns first repeating character from inputted array . This is a part of Mumbai University MCA Colleges C++ Programs MCA 

This program can be modified as to accept user input and also be made in C++ or C Language.


#include<stdio.h>
#include<conio.h>
#include<iostream.h>
char removeDuplicates(char arr[],int n);
void main()
{
 char s[]={'a','b','n','a','b','c'};
 clrscr();
 printf("\nInput Array is: %s\n",s);

 printf("\nFirst Non repeating character Array is: %c\n",removeDuplicates(s,6));
 getch();
}

char removeDuplicates(char arr[],int n)
{
 int i=0,j,cnt,flag=1;
 char c;
 c=arr[0];
 cnt=0;
 for(j=1;j<n;j++)
 {
 for(i=0;i<n;i++)
{ if (cnt==i){}
else
{
if(c==arr[i])
{
flag=0;
cout<<c<<endl;
break;
}
}
}
if(flag==1)
{
return c;
}
       c=arr[j];
       cnt=j;
       flag=1;
  }
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a comment