Program to generate permutation
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int n, i, k = 0;
char a[10];
void perm(char a[10], int k, int n);
clrscr();
printf("Enter the string : ");
scanf("%s", a);
printf("\nThe permutation is :\n");
n = strlen(a);
perm(a, k, n);
getch();
}
void perm(char a[10], int k, int n)
{
char t, d[10];
int i;
if(k == n)
{
printf("\n%s", a);
return;
}
else
{
for(i = k ; i < n ; i++)
{
t = a[i];
a[i] = a[k];
a[k] = t;
strcpy(d, a);
perm(d, k + 1, n);
}
}
}
Output:
Enter the string : abc
The permutation is :
abc
acb
bac
bca
cab
cba
-
UpdatedDec 30, 2019
-
Views12,901
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order