#include<iostream.h>
#include<conio.h>
void
selsort (int *p,int n);
void
main()
{
int a[10],i,n;
cout<<"Enter the value for
n: ";
cin>>n;
cout<<"\nEnter the
elements\n\n";
for (i=0;i<n;i++)
cin>>a[i];
selsort(a,n);
cout<<"\n\nArray after
sorting\n\n";
for (i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
}
void
selsort(int *p, int n)
{
int temp,i,j;
for(i=0;i<(n-1);i++)
for(j=i+1;j<(n);j++)
{
if(*(p+i)>*(p+j))
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
}
}
}
No comments:
Post a Comment