Friday, October 2, 2009

ADA 5th sem lab prgms

/* Program No: 4.
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 if(x[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 scanf("%d",&x[m]);
algorithm();
printf("-------------------------------------\n");
printf("THE SORTED ELEMENTS ARE\n");
printf("-------------------------------------\n");
for(m=0;m printf("%d\n",x[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