/* http://native-code.blogspot.com */
#include<stdio.h>
#include<conio.h>
void input(int*,int) ;
void selection_sort(int*,int) ;
void display(int*,int) ;
void main()
{
int a[30],i,n ;
clrscr();
printf("\n enter the no of element:-") ;
scanf("%d",&n) ;
input(a,n) ;
printf("\n before sort:");
display(a,n);
selection_sort(a,n) ;
printf("\n after sort:");
display(a,n) ;
getch();
}
void input(int*a,int n)
{
int i;
printf("\n enter the no:") ;
for(i=0;i<n;i++)
scanf("%d",a+i);
}
void selection_sort(int*a,int lim)
{
int i,j,tab;
for(i=0;i<=lim-1;i++)
{
for(j=i+1;j<lim;j++)
{
if(*(a+i)>*(a+j))
{
tab=*(a+i) ;
*(a+i)=*(a+j) ;
*(a+j)=tab;
}
}
}
}
void display(int *a,int n)
{
int i;
for(i=0;i<n;i++)
printf("%d",*(a+i));
}
/* http://native-code.blogspot.com */
Post a Comment