You are on page 1of 2

PROGRAM TO SORT AN ARRAY USING BUBBLE SORT

#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[100],n,i,k; cout<<"Enter the number of elements you want to enter\n"; cin>>n; cout<<"Now enter the "<<n<<" number of elements\n"; for(i=0;i<n;i++) { cin>>a[i]; } for(i=0;i<n-1;i++) { for(k=0;k<n-1;k++) { if(a[k]>a[k+1]) { int temp=a[k]; a[k]=a[k+1]; a[k+1]=temp; } } } cout<<"The Sorted list is="; for(i=0;i<n;i++)

{ cout<<a[i]<<"\t"; } getch(); } OUTPUT-

You might also like