The program sorts an array of integers in ascending order using the bubble sort algorithm.
Overall, the program allows the user to enter any number of elements in an array and then sorts the array in ascending order using the bubble sort algorithm. The sorted array is then printed to the console.
#include<iostream> using namespace std; //program to sort an array in ascending order int main() { int a[100],n,i,j,temp; cout<<"\nEnter The Limit : "; cin>>n; cout<<"\nEnter "<<n<<" Value :"<<endl; for(i=0;i<n;i++) { cin>>a[i]; } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } cout<<"\nSorted Array : "<<endl; for(i=0;i<n;i++) { cout<<a[i]<<endl; } return 0; }
Enter The Limit : 10 Enter 10 Value : 2 34 54 2 12 56 7 21 6 1 Sorted Array : 1 2 2 6 7 12 21 34 54 56To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions