Answer to Question #184214 in C++ for Shuvo

Question #184214

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 

ca 

at 

cat


1
Expert's answer
2021-04-22T04:49:16-0400
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cout<<"Input string to print substrings: ";
    cin>>s;
    int count = 0;
    for(int i = s.length() - 1; i >= 0; i--){
        for(int j = 0; j <= i; j++){
            cout<<s[j];
            count = j;
            for(int k = i; k < s.length() - 1; k++){
                cout<<s[count + 1];
                count++;
            }
            count = 0;
            cout<<endl;
        }
    }
    return 0;
}

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