Sorting an array in increasing order using a pointer.
I will get to the code and please keep in mind this code is not for newbie your basics should be clear enough to understand this
#include <stdio.h>
void sort(int *x);
int main()
{
int i;
int a[] = { 0, 23, 14, 12, 9 };
sort(a);
for (i = 0; i <=4; i++)
{
printf("%d\n",a[i]);
}
}
void sort (int *x)
{
int i,temp,j;
for (i = 0; i<=4; i++)
{
for (j = i+1; j<=4; j++)
{
if (*(x + j) < *(x + i))
{
temp = *(x + i);
*(x + i) = *(x + j);
*(x + j) = temp;
}
}
}
}
OUTPUT:
0
9
12
14
23