Answer to Question #188946 in C++ for zain ul abdeen

Question #188946


Q. write a program in c++ that display entered string into reverse order.


1
Expert's answer
2021-05-06T05:20:45-0400
#include<string.h>
#include<iostream>
using namespace std;
void reverseStr(string& str)
{
    int n = str.length();
    for (int i = 0; i < n / 2; i++)
        swap(str[i], str[n - i - 1]);
}
int main()
{
    string s;
    cout<<"Enter a string : ";
    cin>>s;
    reverseStr(s);
    cout<<"\nReversed string : "<<s;
}

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

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS