program get string of arbitrary length in char array
then reverse it and print.
we have to use such for loop
for (i=0,j=(strlen());c;i++,j--)
i know that there is command that do it very easier but i need this one.
C++ program ?
well you can do it this way
string str,
int i;
cout%26lt;%26lt;"\n Enter any string to reverse ";
cin%26gt;%26gt;str;
cout%26lt;%26lt;"\n The string in reverse is ";
length=strlen(str);
for(i=length;i%26gt;0;i--)
{
cout%26lt;%26lt;str[i];
}
or you can do it this way
string str,str2,
int i;
cout%26lt;%26lt;"\n Enter any string to reverse ";
cin%26gt;%26gt;str;
str2="";
for(i=length;i%26gt;0;i--)
{
str2=strcat(str2,str[i])
}
cout%26lt;%26lt;"\n The string in reverse is "%26lt;%26lt;str2%26lt;%26lt;endl;
anyway if you want a single line answer then go for strrev command
cout%26lt;%26lt;"\n enter the string to be reveresed ";
cin%26gt;%26gt;str
cout%26lt;%26lt;strrev(str)%26lt;%26lt;endl;
hope it helps
Reply:Superb %26amp; complete answer. Great!!!!!!!!!!!!!!
Keep on answering. Report It
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment