"Shraddha" <shraddhajoshi84@gmail.comwrote in message
news:1180185229.464276.33190@z28g2000prd.googlegro ups.com...
Quote:
Suppose we are having 3 variables...a,b,c
And we want to print the permutations of these variables...Such
as...abc,acb,bca...all 6 of them...
But we are not supposed to do it mannually...
>
I want to know that formula by which this can be possible...
>
Then that program will be ok for nnumber of variables....
Can anyone help me for that?
>
You've got N! permutations of a string.
So the manual approach breaks down at about 6, the computer approach at
something like N=15.
As the said, Eric Sosman bascially you need to take each element in turn,
then permute the remainder.
So code looks something like this
/*
give user a nice wrapper, permute a string to an output
*/
void permute(char *str, FILE *fpout)
{
char buff[20]; /* you will never need more than 20 characters unless you
have a really super duper computer */
/* start with an empty prefix */
strcpy(buff, "");
permuter(buff, str, fpout);
}
/*
real function is recursive. We print a prefix
*/
static void permuter(char *prefix, char *str, FILE *fp)
{
/* check for strings of length 1, print them (with prefix), and terminate
*/
/* take each element of the string, add it to the prefix, then
call permuter() on the remaining elements */
}
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm