Here we first took the size of array from user as an input 'n', then we we dynamically create memory for those n elements using the malloc function as shown in figure. Next we took the input for elements of array from the user using the for loop, further, we've used two for loop in line 14 and 16 to access i and i+1 element in the array, next in lines from 20 to 22 swapping mechanism has come into play by creating a temp variable.
If you don't understand the swapping technique click here: swapping mechanism to sort array.
Then we print the array, as shown in the line 27 of the code.
No comments:
Post a Comment