aaaaaaa aaaaaab aaaaaac . . . zzzzzzx zzzzzzy zzzzzzz for(i = 0; i #include void iterate(char *str, int idx, int len) { char c; if (idx < (len - 1)) { for (c = 'a'; c <= 'z'; ++c) { str[idx] = c; iterate(str, idx + 1, len); } } else { for (c = 'a'; c <= 'z'; ++c) { str[idx] = c; printf("%sn", str); } } } #define LEN 3 int main(int argc, char **argv) { char str[LEN + 1]; memset(str, 0, LEN + 1); iterate(str, 0, LEN); } #include #include #include int isFinish(char *str){ return ''== str[strspn(str, "z")]; } void inc_str(char *str){ int index, carry; for(index = strlen(str)-1;index>=0;--index){ if(str[index] == 'z'){ carry = 1; str[index] = 'a'; } else { carry = 0; str[index] += 1; } if(carry == 0)break; } } int main(){ int n; char *str; n=7;//length str=(char*)malloc(sizeof(char)*(n+1)); //initialize memset(str, 'a', n);//"aa..aa" str[n]=''; while(1){ printf("%sn", str); if(isFinish(str)) break; inc_str(str); } free(str); return 0; }