0

Hi, where i have mistake? I need to reverse a array

Reverse array https://code.sololearn.com/cvQcF7Ht8xVu/?ref=app

6th Jul 2021, 4:06 PM
Olka Berkovich
Olka Berkovich - avatar
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
6th Jul 2021, 4:12 PM
visph
visph - avatar
- 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; }
6th Jul 2021, 4:28 PM
AbdulWahab
AbdulWahab - avatar