Showing posts with label anagrams for given string. Show all posts
Showing posts with label anagrams for given string. Show all posts

Wednesday, August 19, 2015

Find all ANAGRAMS for given string

ANAGRAMS - all possible string which can be generated by interchanging positions of the letters of given string.

eg. ABC, ACB , BCA , BAC , CAB , ABA all are anagrams




#include <iostream>
using namespace std;
char a[100];
char A[100];
int size_of_string;
void find_anagram(int n)
{
if(n<1){
for(int i=0;i<size_of_string;i++)

cout<<A[i];
cout<<endl;
}else
{
for(int i=0;i<3;i++)
{
A[n-1]=a[i];
find_anagram(n-1);
}
}
}
int main()
{

cout<<"enter the string \n";
cin>>a;
int size=0;

while(a[size]!='\0')
size++;
size_of_string=size;
find_anagram(size);

}

Contributors

Translate