Home c++ The program, which eliminates line of expression in reverse order to the...

The program, which eliminates line of expression in reverse order to the C++

Author

Date

Category

Written by a program, which should display the word lines in the reverse order. Runs without errors, gives to enter a string, but no output.

# include & lt; iostream & gt;
#Include & lt; String & GT;
#Include & lt; algorithm & gt;
Using Namespace STD;
INT MAIN () {
  int i, k, a = 0, dl = 0;
  String str;
  COUT & LT; & LT; "Enter string:";
  dl = str.length ();
  getline (cin, str);
  for (i = dl; i & gt; = 0; i -) {
    a ++;
    if (str [i] == '') {
      for (k = i; k & lt; = (i + a); k ++) {
        COUT & LT; & LT; str [k];
       a = 0;
      }
    }
  }
  Return 0;
}
  • “and” considers the length of each word and is reset after writing the word.
  • I am new to programming, if possible, explain easier.

Answer 1, Authority 100%

Here is the working code:

# include & lt; iostream & gt;
#Include & lt; String & GT;
#Include & lt; algorithm & gt;
Using Namespace STD;
INT MAIN () {
  int i, k, a = 0, dl = 0;
  String str;
  COUT & LT; & LT; "Enter string:";
  getline (cin, str);
  dl = str.length ();
  for (i = dl; i & gt; = 0; i -) {
    if (str [i] == '') {
      for (k = i + 1; k & lt; = (i + a); k ++) {
        COUT & LT; & LT; str [k];
      }
      a = 0;
      cout & lt; & lt; "";
    }
    a ++;
  }
  for (int i = 0; i & lt; dl; i ++) {
    if (str [i] == '') break;
    COUT & LT; & LT; str [i];
  }
  Return 0;
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions