Answer:
See attachment 1 for code
See attachment 2 for the output of permuting letters of parba
See attachment 3 for the output of permuting letters of arbca
Explanation:
The program was implemented in C
The program uses a recursive function letterpermutation and a swap function to successfully implement the requirement of this question.
The letterpermutation function is defined here
void letterpermutation(char *mystring, int index1, int index2) {
This lets the program writes to a file
FILE *fptr;
This opens the file in an appending mode
fptr = fopen("q3out.txt","a");
int i;
This checks for unique strings.
if (index1 == index2) {
If found, this appends the string to the text file
fprintf(fptr,"%s\n",mystring); }
If otherwise
else{
This iterates through the string
for (i = index1; i <= index2; i++) {
The swap function is called to swap the characters of the string
swap((mystring+index1), (mystring+i));
This calls the function, recursively
letterpermutation(mystring, index1+1, index2);
This further swaps the characters of the string
swap((mystring+index1), (mystring+i));
} } }
The swap function begins here and what it literally does is that it swaps characters of the input string to create a new string
<em>void swap(char *ch1, char *ch2) { </em>
<em> char temp; </em>
<em> temp = *ch1; *ch1 = *ch2; *ch2 = temp; } </em>
The main function begins here
int main() {
This declares and initializes the string
char mystring[] = "ABCd"; // The string here can be changed
This calls the function to permute the string
letterpermutation(mystring, 0, strlen(mystring)-1);
return 0; }
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark">
txt
</span>
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark">
txt
</span>
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark">
txt
</span>