181. C Program to Arrange Elements in Ascending Order Using Pointers .
How does this program work?
- This Program is used to arrange elements in ascending order using pointers.
Here is the code
#include <stdio.h>
#include <string.h>
int main ()
{
int n,i,j,temp;
char *a;
printf("Enter size of array:\n");
scanf("%d",&n);
a=calloc(sizeof(int),n);
printf("Enter %d Numbers:\n",n);
for(i=0;i< n;i++)
{
scanf("%d",a+i);
}
for(i=0;i< n-1;i++)
{
for(j=0;j< n-1;j++)
{
if(*(a+j)>*(a+j+1))
{
temp=*(a+j);
*(a+j)=*(a+j+1);
*(a+j+1)=temp;
}
}
}
printf("Array in ascending order after sorting:\n");
for(i=0;i< n;i++)
{
printf("%d\n",*(a+i));
}
return 0;
}