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
Create a project for a sandwich shop. The project, named SalsSandwiches, allows a user to use a ListBox to choose a type of sand
nirvana33 [79]

Answer:

Create a new C# windows application with the name SalsSandwiches. Add the below code in respective file.

Explanation:

See attached images for the source code and output

7 0
3 years ago
What are the five types of pointing devices?
choli [55]

Answer:

mouse, track ball, stick, touch pad, tablet

6 0
3 years ago
You're a ticket agent for a commercial airline and responsible for checking the identification for each passenger before issuing
algol13

Answer:

Follows are the code to this question:

import java.util.*;//import package for user input  

public class Main //defining class  

{

  public static void main(String[] as)//main method

  {

      boolean x,y,z;//defining boolean variable

      Scanner ox= new Scanner(System.in);//create Scanner class object for user input

      System.out.println("input value: "); //print message  

      x=ox.nextBoolean();//input value

      y=ox.nextBoolean();//input value

      z=ox.nextBoolean();//input value

      System.out.println("Output: ");//print message

      System.out.println(x || (y &&z));//use print method to check value and print its value  

  }

}

Output:

1)

input value:  

true

false

false

Output:  

true

2)

input value:  

false

true

true

Output:  

true

3)

input value:  

false

false

false

Output:  

false

Explanation:

In the given code, inside the class three boolean variable "x,y, and z" is declared, that uses the scanner class for input the value from the user end, and in the next print, the method is declared, that uses " OR and AND" gate for calculating the input value and print its value.

In the AND gate, when both conditions are true. it will print the value true, and in the OR gate, when one of the conditions is true, it will print the value true.  

3 0
3 years ago
How do you select a single cell, a single column, a single
Vedmedyk [2.9K]

Answer:

To select nonsequential cells, click the first cell, hold down the Ctrl key, and click each additional cell (or row or column) you want to select. To selectthe entire worksheet, click the small box located to the left of column A and above row 1. Optionally, you can selectall cells in a worksheet by pressing COMMAND+A......

To select all cells on a worksheet, use one of the following methods:

Click the Select All button.Press COMMAND+A. Note If the worksheet contains data, and the active cell is above or to the right of the data, pressing COMMAND+A selects the current region. Pressing COMMAND+A a second time selects the entire worksheet.

8 0
2 years ago
The ______ network became functional in 1969, linking scientific and academic researchers across the United States. Group of ans
denis23 [38]

Answer:

The <u>ARPANET </u>network became functional in 1969, linking scientific and academic researchers across the United States.

Explanation:

ARPA Net is the network that has become functional in 1969 in united States. The basic purpose of this network is to link all the researchers and scientists across united states. The full form of ARPANet is Advanced Research Project Agency Network.

The importance of this network is increase because small chunks of data that are called packets has been proposed for data transmission in the network. The data is divided into small packets and send it over the network, at destination point these packets are combined together and become orignal information.

7 0
3 years ago
Read 2 more answers
Other questions:
  • What might be one reason why a stock becomes more valuable over time
    5·1 answer
  • A programmer wrote the code segment below to display the average of all the elements in a list called numbers. There is always a
    8·1 answer
  • The machine should not be oiled until the
    11·1 answer
  • Microsoft’s SharePoint server product dramatically altered the content and records management (RM) markets. Crocker (2015), edit
    6·1 answer
  • An application programming interface (API) is ________. Select one: A. the code to interface between an application and RAM B. t
    15·1 answer
  • A software package developed to handle information requirements for a specific type of business is called a(n) ____. A. outsourc
    10·1 answer
  • Which of these trade-offs occur in a memory hierarchy?
    15·1 answer
  • Modify the NumberedList class we implementd during the lecture by adding a member function: void NumberedList::insertPosition(in
    13·1 answer
  • What is sampling?
    6·1 answer
  • We cannot imagine a life without the Internet. Imagine that you had to live without being connected to the Internet. Discuss the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!