int main(int argc, char* argv[])
{
        char string[13];
        char tmp[13];
        int len, i, j, k, n=1;

        printf("Length of string: ");
        fgets(string, 13, stdin);
        sscanf(string, "%d", &len);
        if (len > 12) len = 12;

        printf("Enter string: ");
        fgets(string, len+1, stdin);
        string[len] = tmp[len] = 0;

        for(i = 2; i <= len; ++i)
                n *= i;
    printf("There are %d permutations\n", n);

        for(i = 0; i < n; ++i)
        {
                k = i;
                tmp[0] = string[0];
                for(j = 1; j < len; ++j)
                {
                        int indx = k % (j+1);
                        k /= (j+1);
                        tmp[j] = tmp[indx];
                        tmp[indx] = string[j];
                }
                printf("%s\n", tmp);
        }
        return 0;
}

On Apr 8, 1:34 pm, Subhransu <subhransu.panigr...@gmail.com> wrote:
> What could be the efficient  algo for finding permutation of string.
> Lets say a user enter a string "abc".
>
> The output should be 6(3*2*1) along with he combination of them like
>    abc
>    bca
>    cab
>    bac
>    acb
>    cba
>
> *Subhransu Panigrahi
> *
> *Mobile:* *+91-9840931538*
>  *Email:* subhransu.panigr...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to