You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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