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

What is the meaning of && in c?

0 Answers  


how to find sum of 5 digits in C?

4 Answers  


write a progrmm in c language take user interface generate table using for loop?

0 Answers  


to convert a string without using decrement operater and string functions

1 Answers  


what would be the output of the follwing struct st { char name[20]; int i; float f; }; main() { struct st emp = {"forum"}; printf("%d %f",emp.i,emp.f); }

4 Answers  






Consider the following C program. #include <stdio.h> int main() { int i; for (i=0;i<3;++i) { fork();fork(); } } How many processes are created when running this program (including the initial one)? Explain

2 Answers  


What language is c written?

0 Answers  


What is non linear data structure in c?

0 Answers  


Explain 'bus error'?

0 Answers  


Should I learn data structures in c or python?

0 Answers  


12345 1234 123 12 1

2 Answers  


7. Identify the correct argument for the function call fflush() in ANSI C: A)stdout B)stdin C)stderr D)All the above

10 Answers   Accenture,


Categories