446,389 Members | 1,881 Online Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

# printing the permutation, help

 P: n/a Dear group, Given a string I have to print the permutation, using some looping tricks. This is not a Home work problem. My best try as beginner is: #include #include int main(void) { char p[] = "abcd"; int i,j,k; for(i=0;i<4;i++) { printf("first = %c\n",p[i]); } printf("\n"); for(i= 3 ; i < p[i] ; i--) { printf("second = %c\n",p[i]); } printf("\n"); for(i= 2 ; i <= p[i] ;i++) { printf("third = %c\n",p[i]); } return 0; } The first two for loops prints abcd and dcba. But I am not able to proceed further. Can any one guide me. Pls don't write the program instead pls give me a hint. Thanks for any help. Jul 7 '06 #1
6 Replies

 P: n/a the soulution u have will not work. u have to use recursion. check out this program. #include int a[]={1,2,3,4}; permute(int * b,int n) { int i; if(n==1) { for(i=0;i<4;i++) { printf("%d",a[i]); } printf("\n"); return; } int temp; for(i=0;i

 P: n/a #include int a[]={1,2,3,4}; permute(int * b,int n) { int i; if(n==1) { for(i=0;i<4;i++) { printf("%d",a[i]); } printf("\n"); return; } int temp; for(i=0;i 