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
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 |
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 |
A C E G H +B D F A I ------------ E F G H D
What do you mean by c?
Explain what happens if you free a pointer twice?
Explain what is page thrashing?
Implement a function that returns the 5th element from the end in a singly linked list of integers in one pass.
I have a varargs function which accepts a float parameter?
What is the Difference between Class and Struct?
main() { int x=10,y=15; x=x++; y=++y; printf("%d %d\n",x,y); } output??
19 Answers EBS, Ramco, Sangwin, TCS,
Why is c not oop?
Differentiate between #include<...> and #include '...'
What is else if ladder?
pick out the odd one out of the following a.malloc() b.calloc() c.free() d.realloc()