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
Data stored on physical storage devices must do what before the processor can access it? Be converted to binary Be written to th
dsp73

Answer:

Go into short-term memory

Explanation:

Data stored on physical storage devices must go into short-term memory before the processor can access it.

This is because, physical storage devices are secondary memory which store information for a long time. The CPU does not work directly with secondary memory but with primary or short term memory. Since the CPU works mainly with short term memory, information in physical storage or secondary memory has to go into short term memory for the CPU to be able to process it.

<u>So, data stored on physical storage devices must go into short-term memory before the processor can access it.</u>

6 0
3 years ago
You have a Bluetooth headset that integrates with your computer so that you can talk to partners through Microsoft Lync. This is
otez555 [7]
I believe this is an example of a Wireless Personal Area Network (WPAN). This type of network provides a low range wireless network that can interconnect devices near each other. So, Bluetooth devices such as a Bluetooth headset would be an example of WPAN.
5 0
3 years ago
Read 2 more answers
Explain 3 categories of plagiarism​
hammer [34]

Answer:

Direct plagiarism- the word-for-word transcription of a section of someone else’s work, without attribution and without quotation marks

Self-plagiarism- when a student submits his or her own previous work, or mixes parts of previous works, without permission from all professors involved

Mosaic Plagiarism- when a student borrows phrases from a source without using quotation marks, or finds synonyms for the author’s language while keeping to the same general structure and meaning of the original

8 0
2 years ago
Read 2 more answers
Write IF() function for student 3, If total mark is greater than 10 then print
Debora [2.8K]

Answer:

Explanation:

The following code is written in Java. The if() function is actually called an if statement. The following code can be copied and pasted where you need as long as it is within the scope of the mark variable in order to call it and compare it to 10

if (mark > 10){

           System.out.println("you have scored good");  

       } else {

           System.out.println("you need to improve ");

       }

3 0
3 years ago
Assume we are using the simple model for floating-point representation as given in this book (the representation uses a 14-bit f
Artemon [7]

Answer:

The representation of 100.0 in the floating-point representation is computed as follows: First convert the given number 100.0 in the binary form. 10010 = 11001002 the binary representation.

Explanation:

3 0
2 years ago
Other questions:
  • That is Entrepreneur ? ?<br>​
    8·1 answer
  • Word 2013 in order to share a document online you must first
    10·1 answer
  • After a chart has been inserted and formatted, is it possible to change the data range it refers to or to add new rows of data?
    14·1 answer
  • All of the following are advantages of database-stored information, except ______________. Multiple Choice
    7·1 answer
  • 1. If an F# function has type 'a -&gt; 'b when 'a : comparison, which of the following is not a legal type for it? Select one:
    14·1 answer
  • Which option is the correct format of placing HTML tags while coding in HTML?
    13·2 answers
  • Margie has found a stock template to use. She changes a few things about the formatting and then saves the
    7·2 answers
  • In two to three sentences, define "home row" and explain why it is important.
    6·2 answers
  • I need it in code please (python)
    15·2 answers
  • How to create create a database in mysql using clv files
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!