Answer to Question #176300 in C++ for meng

Question #176300

Write a program that reads 5 strings and print them in reverse order.


1
Expert's answer
2021-03-30T02:31:02-0400
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s1, s2, s3, s4, s5;
    cout<<"Enter string 1: ";
    cin>>s1;
    cout<<"Enter string 2: ";
    cin>>s2;
    cout<<"Enter string 3: ";
    cin>>s3;
    cout<<"Enter string 4: ";
    cin>>s4;
    cout<<"Enter string 5: ";
    cin>>s5;


    string s[] = {s1, s2, s3, s4, s5};
    
    cout<<"The strings in reverse order are;";
    for(int i = 0; i < 5; i++){
        cout<<"\n";
        for(int j = s[i].length() - 1; j >= 0; j--)
            cout<<s[i][j];
    }
    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