Some test cases not passing

https://ide.codingblocks.com/s/133496 This is my code. When I declared n and a[n] outside the while loop I was getting a run error. Now random values are getting printed for the array
{-2,-5,6,-2,-3,1,5,-6}. What is the error? Why do we get run time error?

This code is showing correct output in Xcode.

@shruthi019 https://ide.codingblocks.com/s/133525
Check it now.Your mistake was in line number 9. You were declaring the array with size n before taking taking input n.