ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories >> Code-Snippets >> Programming-Code >> C-Code
 
 
 
Question
Write out a function that prints out all the permutations of
a string. 

For example, abc would give you abc, acb, bac, bca, cab,
cba. You can assume that all the characters will be unique.
 Question Submitted By :: Coder_1
I also faced this Question!!     Rank Answer Posted By  
 
Answer
//I think it can be implemented this way rather
simply..check it..

main(){
       char a[15];
       int len,fiblen,i,j,count=0,div,on,to;
       printf("enter the string\n");
       scanf("%s",a);
        fiblen=fib(strlen(a));
        div=fiblen/(strlen(a));
        for(i=0;i<strlen(a);i++){
          for(j=0;j<(strlen(a)-1);j++){
             for(on=1;on<(strlen(a)-1);on++){ 
             to=on+1;        
             swap(&a[on],&a[to]);
             count++;//no: of anagram
             printf("(%d) %s\n",count,a);
             }
          }
             swap(&a[0],&a[i+1]);
        }
 }
       swap(char *a,char *b){
        char temp=*a;
        *a=*b;
        *b=temp;
       }
   int fib(int a){
   if(a==1)
   return(1);
   else
   return(a*fib(a-1));
   }
 
0
Patrick
 
View All Answers
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com