1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
klasskru [66]
3 years ago
13

You are given a 5-letter word (for example, abcde). Write a C-Program which outputs all possible unique 5 letter permutations of

this word in a text file. There should be no repetition of letters in permutation (i.e. in our example, bacde is a valid permutation but bbcde is invalid. Use of library functions for generation of permutations is NOT allowed.
The text file containing the output should be named as q3out.txt. Each word of the output must be on a separate line in the text file. The 5-letter input word should be read by your program from the console. Provide comments in your code. Submit your C code, and the q3out.txt file for the following inputs:
(a) parba
(b) arbca
Computers and Technology
1 answer:
kari74 [83]3 years ago
4 0

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; }

Download txt
<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>
You might be interested in
Snap Me on <br>samxavier.18​
Ahat [919]

Answer:no thank you ima goody

Explanation:

7 0
2 years ago
Read 2 more answers
A_________is a way for students to keep track of information during research.
Fudgin [204]
Note pad your welcome


4 0
3 years ago
Change the shape fill color to Dark Red. It is the first option in the Standard Colors section of the color palette.
maxonik [38]
Is this a question ?
3 0
3 years ago
Digital information is stored using a series of ones and zeros. Computers are digital machines because they can only read inform
ryzh [129]
Is known as the binary system
8 0
3 years ago
Read 2 more answers
Write structured pseudocode to show the following: when you are on time for work you have time to buy coffee
faltersainse [42]

Answer:

If( on_time == True) {

     print("Coffee")

} else {

    print("No Coffee")

}

Explanation:

Step 1 evaluate with a boolean variable if you are on time

If( on_time == True) {

Step 2 if true you have coffee

print("Coffee")

Step 3 if false you have not coffee

print("No Coffee")

3 0
3 years ago
Other questions:
  • How can i complain a rude comment
    7·1 answer
  • How did the invention of the printing press lead eventually to an increase in the diversity of religious expression?
    7·1 answer
  • Why is e-mail better for informative and positive messages than for negative ones?
    6·1 answer
  • Pomógłbymi ktoś z takim zadaniem? C++
    8·1 answer
  • Which design element is used to convey smoothness or roughness in a design
    12·1 answer
  • A project manager type a document and print it he is using
    14·1 answer
  • Which of the following is a strategy used to enhance communication in a presentation?
    14·1 answer
  • To all paladins players out there!!!!!
    14·1 answer
  • If a employee has a grade grater than or equal to 18, then he she will get 50% bonous on the basic pay. Otherwise, the employee
    5·1 answer
  • Why are salaried employees often excluded from overtime pay
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!