Answer to Question #183619 in C++ for shuvo

Question #183619

Write a program that reads a word and prints all sub strings sorted by length. For example, if the user enters the word ”cat”, the program prints

c

a

t

ca

at

cat


1
Expert's answer
2021-04-21T19:19:53-0400
#include <iostream>
#include <string>
using  namespace std;

int main()
{
    string str;
    getline(cin, str);

    int n = str.length();
    for (int i=1; i<=n; i++) {
        for (int j=0; j<=n-i; j++) {
            cout << str.substr(j, i) << endl;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS