Saturday, 14 May 2022

Print all Permutations of a String

C Program to Print all Permutations of a String



 #include<stdio.h>

#include<conio.h>

void swap(char str[],int i,int j)

{

char ch;

ch=str[i];

str[i]=str[j];

str[j]=ch;

}

void fxn(char str[],int l,int r)

{

int i;

if(l==r)

{

printf("%s\n",str);

}

for(i=l;i<=r;i++)

{

swap(str,i,l);

fxn(str,l+1,r);

swap(str,i,l);

}


}

void main()

{

char str[]="ABCD";

clrscr();

fxn(str,0,strlen(str)-1);

getch();

}

output:


Download C Code

#string #stringpermutations #strlen #getch #cprogramming #cpp #c++

#auto #break #case #char

#const #continue #default #do

#double #else #enum #extern

#float #for #goto #if

#int #long #register #return

#short #signed #sizeof #static

#struct #switch #typedef #union

#unsigned #void #volatile #while


#Keywords  #Identifier

#Variables  #Constants

#datatypes

#Input #output #functions

#Operators 


No comments:

Post a Comment