Toh...!Dimmi se ti va bene.codice:#include <stdio.h> #include <string.h> //prototipi di funzione void Swap(char* string,int i,int j); void Permutations(char *string,int i ,int n); void main() { char s[256];//poi per lungezze maggiori ti arrangi tu ma tanto il tempo di esecuzione //cresce col fattoriale e non conviene esagerare con la lungezza.... printf("Dammi la stringa (max 255 caratteri):"); scanf("%s",s); Permutations(s,0,(int)strlen(s)-1); } //Genera ricorsivamente le permutazioni void Permutations(char *string,int i ,int n) { int j; if(i==n) { for(j=0;j<=n;j++) printf("%c",string[j]); printf("\n"); } else { for( j = i ; j<=n ; j++ ) { Swap(string,i,j); Permutations(string,i+1,n); Swap(string,i,j); } } } //Effettua un semplice scambio di posizione void Swap(char* string,int i,int j) { int temp; temp = string[i]; string[i] = string[j]; string[j] = temp; }![]()

Rispondi quotando