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............

Answers were Sorted based on User's Feedback



logic for generating all the combinations of the any number of given letters. ex::::::::: if a,b,..

Answer / 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

logic for generating all the combinations of the any number of given letters. ex::::::::: if a,b,..

Answer / ashok kannan

#include<stdio.h>
#include<conio.h>
#include<string.h>

char a[10];
int m;

void permute(int n,int i)
{
int j;
for(j=i;j<m;j++)
{
printf("%c",a[j]);

if(n!=0)
{
permute(n-1,i+1);
}
else
{
printf("%c\n",a[j]);
}

}

void main()
{
printf("enter the string to be permuted");
scanf("%s",a);
m=strlen(a);
permute(m,0);
}

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More C Interview Questions

which operator is known as dummy operator in c?

2 Answers   Wipro,


Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record

0 Answers   Wipro,


Is struct oop?

0 Answers  


1. Can we use the for loop this way? for(;i>5;) 2. What is the use of pointers? 3. what is array of pointer? 4. What is the difference between file and database? 5. Define data structure?

1 Answers  


Write a program that an operator and two operands read from input operand operator on the implementation and results display.

0 Answers  






what is use of malloc and calloc?

0 Answers  


What is an example of structure?

0 Answers  


why should i select you?

21 Answers   Wipro,


what is a void pointer?

2 Answers  


What is the 'named constructor idiom'?

0 Answers  


What is a global variable in c?

0 Answers  


what is the difference between structural,object based,object orientd programming languages?

1 Answers   PanTerra,


Categories