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
Which header file should you include if you are to develop a function which can accept variable number of arguments?
What is a c token and types of c tokens?
What is operator precedence?
Explain what are compound statements?
Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?
How arrays can be passed to a user defined function
`write a program to display the recomended action depends on a color of trafic light using nested if statments
What should malloc(0) do?
Write a program to generate random numbers in c?
how is the examination pattern?
Explain what is the difference between #include and #include 'file' ?
When is a “switch” statement preferable over an “if” statement?
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.
Why c is called top down?
explain how do you use macro?