Here is the code. I have used a self calling function to create a nested loop of exact size(that is determined by the length of word entered by user) neccessary. I took me about 5hrs to write it and debug it. Have I over did it? Are there any other simpler ways to do it without using any specifically designed c++ library functions?
//PROGRAM TO PRINT ALL PERMUTAIONS OF LETTERS OF A WORD
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char a[11],p[11]; //a to store the word entered
int flag; //p to store a permutaion untill it is printed
void permute(int* chk,int n ,int pos)
{ int i,j,k;
int nxtchk[10];
flag=1;
for(i=0; i<n ; i++ )
{ for(j=0;j<n;j++)
nxtchk[j]=1;
if(chk[i])
{
p[pos]=a[i];
chk[i]=0;
for(j=0;j<=pos;j++)
for(k=0;k<n;k++)
if(p[j]==a[k])
nxtchk[k]=0;
if(pos+1<n)
permute(nxtchk,n,pos+1);
}
}
if(flag) //flag used to ensure each permutation is printed once only
{ cout<<p<<" "; flag=0; }
}
int main()
{
int chk[10]={1,1,1,1,1,1,1,1,1,1};
cout<<"Enter a word whose letters are all different: "; gets(a);
int n=strlen(a);
p[n]='\0';
permute(chk,n,0);
}