![]() |
Reverse array in C++
Hi! I have just started programming, and I have a question for my assignment:
When the input is ABCDE, i want the output to be EDCBA. But for some reason I cant understand he output i get is: EDCDE My code is: " for (int i = 0; i < b; i=i++) { char temp1 = a[i]; a[i] = a[(b-1)-i]; a[(b-1)-i] = temp1; cout << a[i] ; " b is the word... Please help me:) Thank you! |
Re: Reverse array in C++
Just loop it reverse and thats it.
|
Re: Reverse array in C++
> i=i++
Um, no. Either use i++ on its own or use i=i+1. Try as a test displaying the values of i and (b-1)-i in the loop instead. What values do you expect? What values do you get? Does that explain why you get EDCDE? |
Re: Reverse array in C++
how does this grab ya?
Code:
#include <iostream>also i the for loop you put i=i++, i++ will work fine ^^ |
Re: Reverse array in C++
Did you run that code cpulocksmith?
What did word contain after it finished? What's the point of word[i] = word[i]; ? |
Re: Reverse array in C++
ha ha ha... woops...lol...
|
Re: Reverse array in C++
This would do nothing.
char temp1 = word[i]; word[i] = temp1; |
Re: Reverse array in C++
Code:
int size = 5; |
Re: Reverse array in C++
Thank you very much Ryser! It worked :)
|
Re: Reverse array in C++
You dont need value2 array as you are just printing the array from last.
|
| All times are GMT +5.5. The time now is 18:51. |