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 / 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 View All Answers
What is the difference between c &c++?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
How do you do dynamic memory allocation in C applications?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
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
Is fortran faster than c?
What is the difference between abs() and fabs() functions?
hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?
Explain what are multibyte characters?
Here is a neat trick for checking whether two strings are equal
Can you assign a different address to an array tag?
Do you know the purpose of 'register' keyword?
What are linker error?
program for reversing a selected line word by word when multiple lines are given without using strrev
What is an arrays?