In this program, we are going to share a Program for Selection Sort in C++. If you are a beginner and want to start learning the C++ programming, then keep your close attention in this tutorial as I am going to share a program for Program for Selection Sort in C++.
To increase your C++ knowledge, practice all C++ programs:
Copy the below C++ program and execute it with the help of GCC compiler. At the end of this program, We have shared the output of this program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include<iostream> using namespace std; int main() { int i,j,n,loc,temp,min,a[30]; cout<<"Enter the number of elements:"; cin>>n; cout<<"\nEnter the elements\n"; for(i=0;i<n;i++) { cin>>a[i]; } for(i=0;i<n-1;i++) { min=a[i]; loc=i; for(j=i+1;j<n;j++) { if(min>a[j]) { min=a[j]; loc=j; } } temp=a[i]; a[i]=a[loc]; a[loc]=temp; } cout<<"\nSorted list is as follows\n"; for(i=0;i<n;i++) { cout<<a[i]<<" "; } return 0; } |
100010
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.