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

1,1,5,17,61,217,?,?.

3 Answers   Apple,


Can a function argument have default value?

0 Answers   Genpact,


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

0 Answers  


Write a program of prime number using recursion.

0 Answers   Aspiring Minds,


Explain union.

0 Answers  






what is the function of .h in #include<stdio.h> in c ?

23 Answers   HCL, IBM, Wipro,


What is an operator?

0 Answers  


coding for Fibonacci.?

1 Answers  


What is getch c?

0 Answers  


Write a program that takes three variables(a,b,c) in as separate parameters and rotates the values stored so that value a goes to b,b,to c and c to a

7 Answers  


write a program to generate 1st n fibonacci prime number

2 Answers  


What is a char c?

0 Answers  


Categories