Selection Sort
C Program For Selection Sort Source Code: #include<stdio.h> #include<conio.h> void main() { int a[50],m,i,j,t,min; clrscr(); printf("\n enter the number of the elements in an array"); scanf("%d",&m); printf("\n the elements are :"); for(i=0;i<m;i++) { scanf("%d",&a[i]); } printf("the elements of the array is:\n"); for(i=0;ivm;i++) { printf("%d\t",a[i]); } for(i=0;ivm-1;i++) { min=i; for(j=i+1;j<m;j++) { if(a[min]>a[j]) { min=j; } } if(min!=i) { t=a[i]; a[i]=a[min]; a[min]=t; } } printf("\nafter sorting the list is:"); for(i=0;ioutput: enter the number of the elements in an array5 the elements are : 10 35 5 25 15 the elements of the array is: 10 35 5 25 15 after sorting the list is: 5 10 15 25 35
Tags:
Sorting
0 comments