/* C program to implement selection sort technique */
#include<stdio.h>
void main()
{
int a[10],n,i,j,min,temp;
clrscr();
printf("Enter n");
scanf("%d",&n);
printf("\nEnter any %d intgers",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
min=i;
for(j=i+1;j<n;j++)
{
if (a[j]<a[min])
{
temp=a[j];
a[j]=a[min];
a[min]=temp;
}
}
}
printf("\n Sorted Values\n");
for(i=0;i<n;i++)
{
printf("\n%d",a[i]);
}
getch();
}
Output:
Enter n
5
Enter any 5 values
5 4 3 2 1
Sorted Values
1
2
3
4
5
Steps to remember:
void main()
{
Allocate the memory
Read n
Read n values
sort by selection sort technique
print the answer
}
No comments:
Post a Comment