Sort a given set of elements using the Selection Sort method..*/
#include
#include
int x[10], num;
void algorithm()
{
int m,n,situation,low,var;
for(m=0;m
low=x[m];
situation=m;
for(n=m+1;n
low=x[n],situation=n;
var=x[situation];
x[situation]=x[m];
x[m]=var;
}
}
}
void main()
{
int m,n;
printf("ENTER THE NUMBER OF ELEMENTS\n");
scanf("%d",&num);
printf("----------------------------------\n");
printf("ENTER THE %d ELEMENTS\n",num);
printf("----------------------------------\n");
for(m=0;m
algorithm();
printf("-------------------------------------\n");
printf("THE SORTED ELEMENTS ARE\n");
printf("-------------------------------------\n");
for(m=0;m
printf("***********************\n");
getche();
}
/*
Output:
ENTER THE NUMBER OF ELEMENTS
4
----------------------------------
ENTER THE 5 ELEMENTS
----------------------------------
20
10
40
30
-------------------------------------
THE SORTED ELEMENTS ARE
-------------------------------------
10
20
30
40
***********************
*/
No comments:
Post a Comment