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 are the different types of pointers used in c language?
Subtract Two Number Without Using Subtraction Operator
Can a pointer be volatile in c?
Why c is procedure oriented?
Is c procedural or functional?
What is the auto keyword good for?
What is property type c?
What is spaghetti programming?
What is self-referential structure in c programming?
write a program fibonacci series and palindrome program in c
Explain what is the benefit of using #define to declare a constant?
What does s c mean in text?
What is the best way of making my program efficient?
What is extern variable in c with example?
What is methods in c?