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
An additional factor in how an element is rendered is that properties are passed from a parent element to its children in a proc
ValentinkaMS [17]

Answer: Style inheritance

Explanation:

Style inheritance is used to design style sheets. It is a process in which properties are inherited by children from a parent element. For example you wish that all text on a page use same font color i.e. red. You can apply they following style for <body> tag like {body color:red;}. All the elements in the web page will inherit this font color. This is better to use than to create styles for each tag. Every heading and paragraph will be displayed in this font color until you define different color for particular element.

3 0
2 years ago
What would be the best thing you could do to prepare yourself to work for a company that has embraced globalization. A) learn ho
laila [671]

Answer:B

Explanation: your co workers might not know English so you would need to learn their language :)

5 0
3 years ago
Read 2 more answers
A program that will read each player’s name and golf score as keyboard input,
PtichkaEL [24]
Use for loop and question inside it
7 0
2 years ago
Please draw a diagram of a complete graph with 5 vertices (K5), its adjacency matrix and adjacency list representations.
Artist 52 [7]

Answer:

Please check the attachment.

Explanation:

The adjacency matrix is the matrix that has nodes as rows and columns. The nodes if connected is stated as 1 or else 0. And the adjacency list representation is the list with nodes and connected nodes. The nodes that are not connected are not being listed. The diagram and list as well as matrix can be found in the attachment.

4 0
3 years ago
Analyze the following code. II: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java
Grace [21]

COMPLETE QUESTION

I. public class Test {

public static void main(String[] args){

System.out.println("Welcome to Java!");

}

}

II. public class Test { public static void main(String[] args) {System.out.println("Welcome to Java!");}}

Answer:

Both codes will compile and run and display Welcome to Java, but the code in II has a better style than I

Explanation:

When written codes, paying attention to proper coding styles and efficient memory management enables us to create programs that are highly efficient, coding styles refer to proper indentions and avoiding too lenghty lines of code (as is in code I), adding approprite comments etc.

8 0
3 years ago
Other questions:
  • You bought a monochrome laser printer two years ago. The printer has gradually stopped feeding paper. Which printer component sh
    14·1 answer
  • A ____ database supports data distributed across several different sites.
    7·1 answer
  • The feature present in most GUIs that helps organize multiple documents or files is _____.
    5·1 answer
  • A man-made world event that would affect the labor market would be a(n) _____.
    13·1 answer
  • ASAP FAST PLSKara is currently creating a storyboard for her web site. Which step of the web design process is she in? Coding Pl
    9·2 answers
  • Give two reasons you should be aware of your computer's system components and their characteristics.
    10·1 answer
  • I live in Alabama and I’m ab to leave to go on a 3 week trip to France and I’m wondering how I can get LTE for my IPhone 6s Plus
    15·2 answers
  • Write a method named printGPA that takes in as a parameter a Scanner to read in user input, and calculates a student's grade poi
    8·1 answer
  • Date
    6·1 answer
  • Amogus :0) owo have a good day y'all
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!