Reverse the string in C++ by R4R Team

-Here we try to reverse the string and store in another string.

Example-
string is "HEY"
reverse is :"YEH"

program-

#include< iostream.h>
#include< string.h>
int main()
{
char s[20],s1[20];
int i=0,len=0;
//input of string
cout<<"Enter string"< cin>>s;
while(s[i++]!='')
len++;
i=0;
while(s[i]!='')
{
s1[i]=s[len-i-1];
i++;
}
s1[i]='';
cout<<"String in reverse order is: "< }


output-

Enter string
Mystring
String in reverse order is: gnirtsyM

-In this program, we take an input of the string and try to reverse it.
-Firstly find the length of the string.
-Then traverse string in reverse order and store each character in second string.
-At last display that string.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!