How to sorting array with help of pointers?
CODE
How to sorting array with
help of pointers?
//Write a program to
sort an array with help of pointer..
int
main()
{
int n,*p,a[10],i,j,temp;
printf("\n enter N:");
scanf("%d",&n);
p=a;
for(i=0;i<n;i++)
{
printf("\n enter value at
[%d]:",i);
scanf("%d",(p+i));
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(*(p+i)>*(p+j))
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("\n %d",*(p+i));
}
}
Output:
enter N:5
enter value at [0]:1
enter value at [1]:2
enter value at [2]:4
enter value at [3]:8
enter value at [4]:5
8
5
4
2
1
How to sorting array with help of pointers?
Reviewed by Unknown
on
December 31, 2018
Rating:
No comments:
If you have any doubt or query ,comment below: