Home » » Program to find all combination of string in c

Program to find all combination of string in c

This is all find out combination of given string without help of recursion. Its not very simple. Please understand first the given problem


// Simple Program for Calculating Combinations of Given String


#include<stdio.h>
#include<conio.h>
#include<string.h>


void swap(char *a,char *b)
{
char temp=*a;
*a=*b;
*b=temp;
}

void permuteString(char a[],int h)
{
    char b[10],temp[10];
strcpy(b,a);
strcpy(temp,b);
for(int i=0;i<=h;i++)
{
strcpy(b,a);
for(int j=1;j<=h;j++)
{   strcpy(b,a);
for(int k=j;k<=h;k++)
{
swap(&b[j],&b[k]);
printf("%s\n",b);
}

}
swap(&a[0],&a[i+1]);
}

}



void main()
{
char a[]="ABCD";
permuteString(a,strlen(a)-1);
getch();
}

//  Output :




Share this article :

0 comments:

Post a Comment

 
My Other Websites : Ad Networks | Games Copyright © 2014. Study Depth - All Rights Reserved