Interview Questions

given a string write all the possible upper case and lower case strings......

Microsoft Interview Questions and Answers


(Continued from previous question...)

34. given a string write all the possible upper case and lower case strings......

Question:
given a string write all the possible upper case and lower case strings of it. eg. given a string THE print tHE,ThE,THe,thE,The,tHe,the..... give me the solution


maybe an answer:

Using Recursion should yield the required answer
#include<ctype.h>
#include<stdio.h>
#include<string.h>
#include<assert.h>

void toggler(char* x, int pos){
if(pos==0){ printf("%s\n",x); return; }

// printf("String is now: %s\n",x);
x[pos-1] = toupper(x[pos-1]);
toggler(x, pos-1);
x[pos-1] = tolower(x[pos-1]);
toggler(x, pos-1);

return;
}

int main(void){
char str[500];
scanf("%s",str);
toggler(str, strlen(str));
return 0;
}




maybe an answer2:

Idea is very Simple,We can use the concept of subset generation but here for
0-Lower case
1-Upper Case
With the given example "the/THE"
000-the
001-thE
010-tHe
011-tHE
100-The
101-ThE
110-THe
111-THE

(Continued on next question...)

Other Interview Questions