Solution #1: This can be easily solved by recursion. Fix one letter to either uppercase or lowercase and permute rest of the letters. Here is the code,
#include#include #include #include void toggle(char* str, int n) { if(n == strlen(str)) { printf("%s\n", str); return; } str[n] = toupper(str[n]); toggle(str, n+1); str[n] = tolower(str[n]); toggle(str, n+1); } int main() { char str[50] = {0, }; sprintf(str, "suchit maindola"); toggle(str, 0); return 1; }
No comments:
Post a Comment