Westonci.ca is the ultimate Q&A platform, offering detailed and reliable answers from a knowledgeable community. Get detailed and precise answers to your questions from a dedicated community of experts on our Q&A platform. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.
Sagot :
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
void swap(char *ch1, char *ch2) {
char temp;
temp = *ch1; *ch1 = *ch2; *ch2 = temp; }
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; }
Thanks for using our service. We're always here to provide accurate and up-to-date answers to all your queries. Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. Stay curious and keep coming back to Westonci.ca for answers to all your burning questions.