Question

Write a C program that … reads (from standard input) five words, with each of the...

  • Write a C program that …
    1. reads (from standard input) five words, with each of the words being entered on a separate line
    2. prints (to standard output) the words in reverse alphabetical order
  • Hints
    • http://www.cplusplus.com/reference/cstring/strcmp
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello, here is the completed code you wanted. Every important statement is explained using comments. Please check and let me know if you have any doubts. Thanks.

CODE

//library for standard input and output
#include<stdio.h>

//main function
int main()
{
   //variables
   char words[5][100], temp[100];
   int i, j;
  
   //prompt for words
   printf("Enter 5 words:\n");
  
   //loop for reading words into array
   for(i = 0; i < 5; i++)
   {
       //reading words
       scanf("%s", words[i]);
   }
  
   //outer loop for sorting
   for (i = 0; i < 5; i++)
    {
       //inner loop for sorting
        for (j = i + 1; j < 5; j++)
        {
           //comparing words and sorting
           if(strcmp(words[i], words[j]) < 0)
           {
               strcpy(temp, words[i]);
               strcpy(words[i], words[j]);
               strcpy(words[j], temp);
           }
       }
   }
  
   //loop for printing words in reverse alphabetical order
   printf("\nwords in reverse alphabetical order:\n");
   for(i = 0; i < 5; i++)
   {
       //printing words
       printf("%s\n", words[i]);
   }
}

OUTPUT

CODE SCREEN SHOT

Add a comment
Know the answer?
Add Answer to:
Write a C program that … reads (from standard input) five words, with each of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program such that … the program receives ( following argv[0] ) one or...

    Write a C program such that … the program receives ( following argv[0] ) one or more integer values as command line arguments the program prints (to standard output) … the command line arguments, with each appearing on a separate line the sum of the integer values that follow argv[0] Hints http://www.cplusplus.com/reference/cstdlib/strtol THE CORRECT OUTPUT OF THE TEST CASE : The command line arguments are ... argv[0] ... "./a.out" argv[1] ... "2" argv[2] ... "9" argv[3] ... "-100" argv[4] ......

  • Write a C program that … reads one unsigned long int value  N  from standard input...

    Write a C program that … reads one unsigned long int value  N  from standard input assume that the value of  N  that is entered by the user is greater than  1  prints (to standard output) … the greatest prime number that divides of  N 

  • I/O program for C Write a program in direct1.c which reads from standard input a line...

    I/O program for C Write a program in direct1.c which reads from standard input a line and then outputs that line immediately to standard output. it should read the first line only ! Then, write another program called direct2.c which reads from standard input every line until end of input and outputs them to standard output. Everything that goes in should come out exactly as it was. Compile both programs and run them on the input files given below The...

  • Write a C program that … reads a sequence of one or more double values from...

    Write a C program that … reads a sequence of one or more double values from standard input, one-after-another stops reading double values as soon as a negative value is entered then prints (to standard output & with precision 2) … the average of the positive values that were entered

  • Python 3 Write a program that reads a sequence of words and prints every word whose...

    Python 3 Write a program that reads a sequence of words and prints every word whose frequency is equal to its length. You can assume that there will always be a word that meets this condition. If more than one word have this condition, you must print first the most frequent one. If two or more words with equal frequencies meet this condition, print them from the smallest to the largest in alphabetical order. Sample Input lee john lee peter...

  • Write a Java program that reads in 5 words from the user and stores these words...

    Write a Java program that reads in 5 words from the user and stores these words in a String array. Then your program needs to print 2 lines of output with the following information: All words are in reverse order (based both on content and order). Every word at an even index of the array (i.e., indices 0, 2, and 4). For example, if user inputs "ABC", "DEF", "TY", "JK", and "WE". Then your program should output the following two...

  • In c programming, I need to write a program that reverses each of the lines in...

    In c programming, I need to write a program that reverses each of the lines in a file. The program accepts two command line arguments: The first one is the name of the input file The second is the name of the output file If the user didn't give two filenames, display an error message and exit. The program reads in each line of the input file and writes each line in reverse to the output file. Note, the lines...

  • Write a program file_max.c that reads a set of integer numbers from a file and prints...

    Write a program file_max.c that reads a set of integer numbers from a file and prints out the maximum number to standard output. The name of the input file should be specified as a command line argument.

  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • Write a Java program that reads in a word from the user and outputs each character...

    Write a Java program that reads in a word from the user and outputs each character of the word on a separate line. For example, if the user enters the input "Joe", your program should output: J o e You need to use a for-loop.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT