logic for generating all the combinations of the any number
of given letters.
ex:::::::::
if a,b,c,d are given the o/p should be
abcd,dcba,dbac,bcad,................
4*3*2*1 combinations............

Answer Posted / abdur rab

#include <stdio.h>

void permute ( char* strptr, int start, int length )
{
int count1;
int count2;
int temp;

for ( count1 = start; count1 < length - 1;
++count1 ) {
for ( count2 = count1 + 1; count2 < length;
++count2 ) {
temp = strptr [ count1 ]; strptr [
count1 ] = strptr [ count2 ]; strptr [ count2 ] = temp;
permute ( strptr, count1 + 1,
length );
temp = strptr [ count1 ]; strptr [
count1 ] = strptr [ count2 ]; strptr [ count2 ] = temp;
}
}
printf ( "\n%s", strptr );
}

int main ( int argc, char* argv [] )
{
char str[] = "abcd";

permute ( str, 0, ( strlen ( str ) ) );

return 0;
}

Is This Answer Correct ?    7 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is uses of .net

1485


Why is c platform dependent?

819


Is c# a good language?

801


write a program to print largest number of each row of a 2D array

2106


Why is structure padding done in c?

904


write a program to concatenation the string using switch case?

1823


How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

808


What is union and structure in c?

882


Are there namespaces in c?

805


Explain the use of 'auto' keyword

890


Explain what is the general form of a c program?

833


what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above

906


What is huge pointer in c?

782


What is void main ()?

816


What does typeof return in c?

856