Q. write a program in c++ that display entered string into reverse order.
#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;
}
Comments
Leave a comment