Question

Using C programming

Write a program that asks the user for a sentence and displays the following four things. They are in increasing order of difficulty.

  1. How many characters in that sentence? [12]

  2. How many words in that sentence? [3]

  3. The sentence backwards [dooG sI efiL]

  4. The words (not the letters) shown in reverse order (not mandatory! this one is hard!!) [Good Is Life]


0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>


int main(){

   int i,j;

   char str[]="Life Is Good";

   printf("Length of sentence : %d\n",strlen(str));

   int words=1;

   int indices[10];

   char strrev[sizeof(str)];

   char strwordsrev[sizeof(str)];

   int k;

   k=0;

   for(i=0;i<strlen(str);i++){

      if(str[i]==' '){

         words=words+1;

         indices[k]=i;

         k=k+1;

      }

   }

   indices[words-1]=strlen(str);

   printf("Words in sentence: %d\n",words);

   for(i=strlen(str);i>=0;i--){

      strrev[strlen(str)-1-i]=str[i];

   }

   printf("Sentence in reverse: ");

   for(i=0;i<strlen(strrev);i++){

      printf("%c",strrev[i]);

   }

   printf("\nWords in reverse: ");

   int temp=0;

   for(i=0;i<words;i++){

      j=0;

      while(1){

         printf("%c",strrev[indices[i]-j]);

         j=j+1;

         if((indices[i]-j)==temp-1){

            temp=indices[i];

            break;

         }

      }

   }

   

   

}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
Using C programming
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 program in java that asks the user for a sentence, and then returns that...

    write a program in java that asks the user for a sentence, and then returns that string with the words backwards. For example: Enter a sentence! Mary had a little lamb. Your sentence backwards: lamb. little a had Mary Write a method called reverse() that accepts a sentence as a string, and then returns that string with the words backwards. Write a main() method that gets the string from the user and then displays the string backwards. demonstrate program by...

  • 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...

  • matlab code Question : Not yet answered Marked out of 10.00 Flag question Build a MATLAB...

    matlab code Question : Not yet answered Marked out of 10.00 Flag question Build a MATLAB program that asks the user to enter a string which is composed of an English sentence that has at least 5 words. Your task is to build a function that counts and displays the number of words inside the sentence. Additionally, you need to build another function that displays the whole sentence in reverse order without using the bulk in function reverse Paragraph в...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Please help with writing this code. The language is C++. I'm using vim. Thanks Problem Statement...

    Please help with writing this code. The language is C++. I'm using vim. Thanks Problem Statement A good password has many requirements. Humans have a hard time meeting these requirements left to their own devices. You are tasked with creating a program that will generate a password based on what the user wants in the password The user should be able to choose if they want a password with: letters upper case "lower case *numbers The user should also provide...

  • Write a program in java that asks a user for a file name and prints the...

    Write a program in java that asks a user for a file name and prints the number of characters, words (separated by whitespace), and lines in that file. Then, it replaces each line of the file with its reverse. For example, if the file contains the following lines (Test1.txt): This is a test Hi there Output on the console: Number of characters: 22 Number of words: 6 Number of lines: 2 Data written to the file (Test1.txt): tset a si...

  • Use C++ language, keep it simple Exercise #2: Strings' operations Write a C++ program that prompts...

    Use C++ language, keep it simple Exercise #2: Strings' operations Write a C++ program that prompts the user to enter a sentence, the program then does the following: 1. Prints the total characters in the sentence. 2. Prints the word count of the sentence, assuming only one space between each tow words. 3. Prints total vowel (a, e, i, o, u) in the sentence. 4. Prints the vowel frequency as shown in the sample below. 5. Prints the sentence in...

  • In c++ please .. Write a program that prompts the user to enter a four-digit integer...

    In c++ please .. Write a program that prompts the user to enter a four-digit integer and displays the number in reverse order.

  • Exercise 1: Write a C++ program that asks the user to input an integer n followed...

    Exercise 1: Write a C++ program that asks the user to input an integer n followed by n other characters that will be stored in an array. We suppose here that the user will input only lowercase characters between ‘a’ and ‘z’. We also suppose that the user will input different characters. The program will then sort these characters according to an increasing order of their alphabetical order. In this exercise, feel free to use selection sort, insertion sort, or...

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

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
ADVERTISEMENT