From a183fdf6578faa31c0c0b02f248347f055db6804 Mon Sep 17 00:00:00 2001 From: PrateekSingh009 <56078678+PrateekSingh009@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:08:19 +0530 Subject: [PATCH] Stringpermutation.c For printing all possible permutation of any string --- Ch 01. Arrays and Strings/Stringpermutation.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Ch 01. Arrays and Strings/Stringpermutation.c diff --git a/Ch 01. Arrays and Strings/Stringpermutation.c b/Ch 01. Arrays and Strings/Stringpermutation.c new file mode 100644 index 0000000..a3eb1db --- /dev/null +++ b/Ch 01. Arrays and Strings/Stringpermutation.c @@ -0,0 +1,34 @@ +#include +void swap(char *p,char *q) +{ +char temp; +temp=*p; +*p=*q; +*q=temp; +} +void permute(char *a,int l,int r) +{ +int i; +if (l==r) +printf("%s\n", a); +else +{ +for (i=l;i<=r;i++) +{ +swap((a+l),(a+i)); +permute(a,l+1,r); +swap((a+l),(a+i)); +} +} +} +void main() +{ +char str[100]; +printf("Enter the String\n"); +gets(str); +printf("\n"); +int n = strlen(str); +printf("All permutations are :\n"); +permute(str,0,n-1); + +}