Issue with function to generate letter combinations in c++ -


i trying create function output possible combinations of letters, alternating consonants , vowels. should output:

consonant + vowel + consonant + vowel + consonant + vowel --or-- bababa...

i have first 2 letters outputting correctly, i'm stuck on adding more. problem put loops after below.

i'm cout-ing on console (for testing), once it's working i'm going output file later reference.

void createword(char consonants[], char vowels[]) { //clength = 21, , vlength = 5, consonants[] cstring consonants, , vowels[] cstring vowels.  int i, j; (i = 0; < clength; i++) {      (j = 0; j<vlength; j++)     {         cout << consonants[i] << vowels[j] ;         cout << endl;     } }  } 

like surprising number of "generate combinations" type of problems, can solved counting.

start couple of strings convert numeric character representation:

char const *consonants[] = "bcdfghjklmnpqrstvwxyz"; char const *vowels[] = "aeiou"; 

the can count, , use right parts of our number indices arrays:

// i'll arbitrarily pick 10000 number print out. (size_t i=0; i<10000; i++) {     size_t digit_0 = % 21;     /= 21;     size_t digit_1 = % 5;     /= 5;     size_t digit_2 = % 21;     /= 21;     size_t digit_3 = % 5;      std::cout << consonants[digit_0]                << vowels[digit_1]                << consonants[digit_2]                << vowels[digit_3]                << "\n"; } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -