0
Hi, where i have mistake? I need to reverse a array
Reverse array https://code.sololearn.com/cvQcF7Ht8xVu/?ref=app
2 Answers
+ 1
your logic is wrong: your code reverse the array twice (so do not reverse it)...
to reverse an array inplace do your loop only for i < length/2...
then do another complete loop to output each items ;P
- 1
i made changes but it reverse back in the middle. result : 894498
#include <stdio.h>
int main() {
int array [6]= {2, 3, 5, 4, 9, 8};
for(int i =0; i<6; i++){
int tmp = array[6-i-1 ];
array[6- i-1] = array [i];
array[i]= tmp;
printf("%d", tmp);
}
return 0;
}