Write a program that reads 5 strings and print them in reverse order.
#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;
}
Comments
Leave a comment