The code is not passing test cases

i have written the code which is not passing any test cases.but sample test case is passed.Please tell me error

your code is not giving output according to question’s requirement
for input
4
3 4 2 1
correct output is
1 2 3 4
but your output is
1
2
3
4

your output should be exactly according to question

make one small change after that your code pass all testcase
instead of endl give some space
for(i=0;i<n;i++)
cout<<ar[i]<<" ";

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

we are reaching the index -1 at the termination o while loop.Is there any way by which we can avoid it

According to your code this will happen

You can manage it after completion while loop