0
Write a program which can interchange/swap elements in such a way that the first element is swapped with last element and so on.
Actually the question is Write a program which can interchange/swap elements in such a way that the first element is swapped with last element ,second element is swapped with the second last element and so on, only if anyone or both the elements are odd. E.g.If initially array of 7 elements is: 5,16, 4, 7, 19, 8, 2 After execution 2, 16, 19, 7, 4, 8, 5 https://code.sololearn.com/cgJMOUz638Em/?ref=app
2 Réponses
+ 7
First of all if you are taking array size by the user then you have to create dynamic array.
Dynamic arrays are created on heap and their size is determined at runtime.
Secondly, in your if condition replace ar[n-1] with ar[(n-1)-i] and the program should work.
Third, you don't need to decrement n.
Edit: Replace ar[n-1] with ar[(n-1)-i] everywhere in your code.
0
Thanks for answering and why can't i use ar [n-1]