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
what is uses of .net
Why is c platform dependent?
Is c# a good language?
write a program to print largest number of each row of a 2D array
Why is structure padding done in c?
write a program to concatenation the string using switch case?
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
What is union and structure in c?
Are there namespaces in c?
Explain the use of 'auto' keyword
Explain what is the general form of a c program?
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
What is huge pointer in c?
What is void main ()?
What does typeof return in c?