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

Which header file should you include if you are to develop a function which can accept variable number of arguments?

815


What is a c token and types of c tokens?

594


What is operator precedence?

647


Explain what are compound statements?

608


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

660






How arrays can be passed to a user defined function

581


`write a program to display the recomended action depends on a color of trafic light using nested if statments

1635


What should malloc(0) do?

619


Write a program to generate random numbers in c?

666


how is the examination pattern?

1599


Explain what is the difference between #include and #include 'file' ?

591


When is a “switch” statement preferable over an “if” statement?

653


Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

1524


Why c is called top down?

632


explain how do you use macro?

670