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

        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] = 0;

        n = 1;
        for(i = 0; i < len; ++i)
                n *= i+1;

    printf("There are %d permutations\n", n);
        for(i = 0; i < n; ++i)
        {
                for(j = 0; j <= len; ++j)
                        tmp[j] = string[j];
                k = i;
                for(j = 0; j < len; ++j)
                {
                        int indx = j + (k % (len-j));
                        char t=tmp[indx];
                        tmp[indx] = tmp[j];
                        tmp[j] = t;
                }
                printf("%s\n", tmp);
        }


        return 0;
}


On Apr 8, 1:34 pm, Subhransu <[email protected]> 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:* [email protected]

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

Reply via email to