0
j+e's Avatar, Join Date: Feb 2009
j+e
Light Poster
Thank you very much! That helped, because I found out that the letters where shuffled to EDCBA, and then shuffled back to ABCDE. So I just said that:

for (int i = 0; i < (b-((b+1)/2)); i++)

because odd number/2 will be rounded down, this works!

Maybe not the best way to do it in a programmers view, but it worked
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
> Maybe not the best way

On the contrary, reversing a string by only looping over the first half, rounded down, is very efficient.
Just to make sure though, try a even number length string, e.g. ABCDEFGH, make sure you get the correct output.
0
j+e's Avatar, Join Date: Feb 2009
j+e
Light Poster
I have tried that, and it works out perfectly well. Even though setences!!

Again, thanks for your help!
0
ijax's Avatar, Join Date: Oct 2011
Newbie Member
The code you guys entered is not correct,,, cause you have to reverse it along with its place,,,
here this may be helpful

#include<iostream.h>
#include<conio.h>
using namespace std;
main()
{
cout<<"Enter The Number Alphabets your Word has \t";
int x;
cin>>x;
cout<<"Enter Your Word:";
char a[x];
cin>>a;


char temp;

for (int i=x; i>=0;i--)
{
temp=a[i];
a[i]=temp;
cout<<a[i];
}
cout<<endl;
getch();
}
0
mukeshsoftona's Avatar
Banned
It's correct coding dear. it's run i am sure.
Thanks for sharing it.