Hi, Here explains the program for sorting of given number of...

advertisement
Hi,
Here explains the program for sorting of given number of elements in ascending order using the concept
of selection sort with the help of the programming language C. Proper header files must be included at
the time of execution of this program. In this program, must include the following header files: stdio.h
and conio.h. The output for the selection sorting is also given along with this. This program helps you to
understand about the sorting of given number of elements in ascending order using the concept of
selection sort. Please check the program and give back replay about this program.
void main()
{
int n,i,j,temp,num[50];
clrscr();
printf(“Enter the limit\n”);
scanf(“%d”,&n);
printf(“Enter the elements for sorting\n”);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(num[i]>num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf(“Sorted elements are:\n”);
for(i=0;i<n;i++)
printf(“%d\t”,num[i]);
getch();
}
Output of the above program:
Enter the limit
6
Enter elements for sorting
8
5
1
10
7
12
Sorted elements are:
1
5
7
8
10
12
Download