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
|
Light Poster
|
|
| 22Feb2009,19:01 | #21 |
|
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
|
|
Mentor
|
![]() |
| 22Feb2009,20:07 | #22 |
|
> 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. |
|
Light Poster
|
|
| 22Feb2009,20:50 | #23 |
|
I have tried that, and it works out perfectly well. Even though setences!!
![]() Again, thanks for your help! |
|
Newbie Member
|
|
| 26Oct2011,19:23 | #24 |
|
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(); } |
|
Banned
|
|
| 2Nov2011,15:40 | #25 |
|
It's correct coding dear. it's run i am sure.
Thanks for sharing it. |