# Using Pointers Sort Array

By | December 9, 2022

Using Pointers Sort Array – Write a program in C Programming Language To input N numbers and arrange it in Ascending Order.

### Using Pointers Sort Array – C Source Code

```#include <stdio.h>
void main()
{
int *ptr,a[100],i,j,temp,n;
printf("\n\n Using C Pointers : Sort an array using pointer :\n");
printf("----------------------------------------------------\n");

printf(" Enter the size of array : ");
scanf("%d",&n);
ptr = a;
printf(" Enter %d number of elements in the array : \n",n);
for(i=0;i<n;i++)
{
printf(" Enter Element No: %d : ",i+1);
scanf("%d",ptr+i);
}

for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if( *(ptr+i) > *(ptr+j))
{
temp = *(ptr+i);
*(ptr+i) = *(ptr+j);
*(ptr+j) = temp;
}
}
}
printf("\n The numbers in the array after sorting are: \n");
for(i=0;i<n;i++)
{
printf("  %d \n",*(ptr+i));
}
printf("\n");
}
```

Output

Using C Pointers : Sort an array using pointer :
—————————————————-
Enter the size of array : 5
Enter 5 number of elements in the array :
Enter Element No: 1 : 123
Enter Element No: 2 : 65
Enter Element No: 3 : -4
Enter Element No: 4 : 90
Enter Element No: 5 : 2

The numbers in the array after sorting are:
-4
2
65
90
123

——————————–
Process exited after 20.79 seconds with return value 10
Press any key to continue . . .

You may also like: