to sort array with pointer in c

void main()
{
int i,j,temp;
int arr[9]={-1,3,3,0,11,2,-5,88,1};
int *ptr;
clrscr();

for(i=0;i<9 data-blogger-escaped-div="" data-blogger-escaped-i="">
{
for(j=i+1;j<9 data-blogger-escaped-div="" data-blogger-escaped-j="">
{
if(*(i+arr)>*(j+arr))
{
ptr=arr+i;
temp=*ptr;
ptr=arr+j;
*(arr+i)=*ptr;
*(arr+j)=temp;
}
}
}
for(i=0;i<9 data-blogger-escaped-div="" data-blogger-escaped-i="">
printf(" %d",arr[i]);
getch();
}
Output: -5 -1 0 1 2 3 3 11 88

Post a Comment