Write permutation series i.e ABC, BCA, ACB, CAB, CBA...

Showing Answers 1 - 1 of 1 Answers

#include<stdio.h>
void permute(int n, int size, char array[])
{
    char tmp;
    int i, j;

    if (n == 1) {
    for (i = 0; i < size; i++)
     putchar(array[i]);
    putchar('n');
    } else {
    for (i = 0; i < n; i++) {
     permute(n - 1, size, array);
 j = (n % 2 == 1) ? n - 1 : 0;
 tmp = array[n - 1];
 array[n - 1] = array[j];
 array[j] = tmp;
 }
    }
}
void main()
{
 permute(4, 4, "abcd");
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions