belongs to collection: Sorting C Programs
Selection Sort is the most simplest Sorting Technique, in this sorting technique first finds the smallest or largest element (depending on the order that you want to do) and swaps the smallest or largest elements with the corresponding element.
#include int main() { int s,i,j,temp,a[20]; printf("Enter total elements: "); scanf("%d",&s); printf("Enter %d elements: ",s); for(i=0;i scanf("%d",&a[i]); for(i=0;i for(j=i+1;j if(a[i]>a[j]){ temp=a[i]; a[i]=a[j]; a[j]=temp; } } } printf("After sorting is: "); for(i=0;i printf(" %d",a[i]); return 0; }
Output:
Enter total elements: 5
Enter 5 elements: 12
45
-56
0
151
After sorting is :-56 0 12 45 151
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
Enter total elements: 5
Enter 5 elements: 12
45
-56
0
151
After sorting is :-56 0 12 45 151
need an explanation for this answer? contact us directly to get an explanation for this answer