Returns First Repeating Character from Array

Ram Pothuraju
This program is to Returns first repeating character from inputted array . 


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;
  }
}
Tags

Post a Comment

0Comments

Post a Comment (0)