This is, because you initialise the array a with the size n in the first line of main(). At this point, n is not set, its value is indeterminate. Hence the segmentation fault.
So declare your array a, after the value n is read.
Now, your code will run.
Unfortunately, the sorting does not work correctly, so you need to fix that too.
Have a look at this for various sorting algorithms: https://www.geeksforgeeks.org/sorting-algorithms/
I'd focus on the Bubble Sorting, as it's easy to understand. It's not too effective, but you should have a working code first and worry about efficiency later.
If you fancy a better sorting that's a bit harder to understand, look at the Quick Sort algorithm.