Showing posts with label finding permutation of string in c. Show all posts
Showing posts with label finding permutation of string in c. Show all posts

Friday, 19 February 2016

Program To Find "PERMUTAION" of String in C++

"Nice One Program"

// Here Is The CODE for The program

//Observe it Carefully
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{  char a[10],b[10],i,j;
   int l1,l2;
   clrscr();
   cout<<"PROGRAM TO CHECK PERMUTATION\n\n";

   cout<<"Enter The Original Word:-";
   cin>>a;
   cout<<"\nEnter The Word For checking Permutation:-\n\n";
   cin>>b;
   l1 = strlen(a);
   l2 = strlen(b);

   // HERE WILL  THE ACTUAL THING START

    if(l1!=l2)
   { cout<<"It Is NOT a Permutation Of Given Number\n";   }

    else

{ // sorting  for original
     int t1,t2;char t;

     for(i=0;i<l1;i++)
     for(j=0;j<l1-1-i;j++)
   {
       t1=a[j];
       t2=a[j+1];

       if(t1>t2)
      { t=a[j];
 a[j]=a[j+1];
 a[j+1]=t;
 }
   }


    //sorting Second one
    for(i=0;i<l1;i++)
    for(j=0;j<l1-1-i;j++)
    { t1=b[j];
      t2=b[j+1];
      if(t1>t2)
     {
       t=b[j];
       b[j]=b[j+1];
       b[j+1]=t;
     }
    }

   if(strcmp(a,b)==0)
   cout<<"\n\nYES IT IS A PERMUTAION OF GIVEN";
   else
   cout<<"\n\nIT IS NOT A PERMUTAION OF GIVEN";
}

   getch();    return 0;
     }


HERE ARE BOTH THE OUTPUTS: