COMPARISON OF TWO STRING WITHOUT USING BUILTIN FUNCTION

#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
main()
{
 clrscr();
 char a[25],b[25];
 int cnt=1,i=1;
 cout<<"\n ENTER THE STRING 1 : ";
 cin>>a;
 cout<<"\n ENTER THE STRING 2 : ";
 cin>>b;

 while(a[i]!='\0' && b[i]!='\0')
 {
  if(a[i]==b[i])
  {
   cnt++;
  }
  else
  {
   cout<<"\n\n THE TWO STRINGS ARE NOT EQUAL";
  }
  i++;
 }

 if(i==cnt)
 {
  int n;
  clrscr();
  cout<<"\n\n\t\t----------------------------------COMPARISON RESULT------------------";
  cout<<"\n\n THE GIVEN TWO STRINGS ARE EQUAL ";
 }

 getch();
 return 0;
}

No comments:

Post a Comment