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
Which of the following is the largest unit of information?
Mila [183]
What are the choices?

5 0
4 years ago
Read 2 more answers
Which of the following best describes the difference between software and hardware?
s344n2d4d5 [400]

I believe the answer is A.

7 0
3 years ago
Read 2 more answers
When coding, how do you get animations to work??
Nina [5.8K]

Answer:

Blender's animation & rigging if you are talking about 3d modeling.

Explanation:

Blender is a standard free to use universally used software used in animation for most standard games. You learn to model, then to rig with bones, then to animate. Animations don't entirely go with coding unless you are calling them in the code to make them play.

7 0
4 years ago
4.2: Roman Numeral Converter
dalvyx [7]

Answer:

1 I

2 II

3 III

4 IV

5 V

6 VI

7 VII

8 VIII

9 IX

10 X

6 0
3 years ago
What is the signifigance of the following sentence in relation to font? The quick brown fox jumps over the lazy dog? A. It has e
Talja [164]
D. Is your answer for the question. Tell me if this helps!
6 0
4 years ago
Other questions:
  • A small company connects data acquisition equipment to the serial port of a computer. The equipment user has reported that not a
    8·1 answer
  • When viewing data entered into a spreadsheet, the columns identify _____.?
    5·1 answer
  • What is the advantage of defining a target user?
    6·1 answer
  • A cell reference with only one dollar sign before either the column or the row is called an absolute reference.
    10·1 answer
  • Assume a PHP document named hello.php has been saved in a folder named carla inside the htdocs folder on your computer. Which is
    11·1 answer
  • What operation can be performed using the total feature ​
    13·1 answer
  • A carver begins work on the following block of granite that weighs 2700 g. What is the density of the granite?
    13·1 answer
  • When two well-informed people have different perspectives on a problem, it is often because they are focusing on a different app
    12·1 answer
  • Your computer science teacher asks you to sample a black and white image that is 4” x 6”. How would you sample the image to prov
    10·1 answer
  • Can you help me in my work
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!