programming-examples/c++/Combinational_Problems/C++ Program to Find the Number of Permutations of a Given String.cpp
2019-11-15 12:59:38 +01:00

46 lines
733 B
C++

/*
* C++ Program to Find the Number of Permutations of a Given String
*/
#include<stdio.h>
#include<conio.h>
#include<iostream>
using namespace std;
void swap (char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
void permute(char *a, int i, int n)
{
int j;
if (i == n)
{
cout<<a<<endl;
}
else
{
for (j = i; j <= n; j++)
{
swap((a + i), (a + j));
permute(a, i + 1, n);
swap((a + i), (a + j));
}
}
}
int main()
{
char a[] = "ABC";
permute(a, 0, 2);
getch();
}
/*
ABC
ACB
BAC
BCA
CBA
CAB