Created
November 10, 2015 17:09
-
-
Save nalin-adh/cb519aa8553f7f68cc8c to your computer and use it in GitHub Desktop.
A C++ program to sort n numbers in ascending order using bubble sort.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<conio.h> | |
using namespace std; | |
void display(int b[]); | |
int main() | |
{ | |
int a[]={9,5,3,7,4,6,1,2,8,9,4,5,6,2,0},n; | |
cout<<"Numbers before BUBBLE SORT :\n"; | |
display(a); | |
cout<<"\nNumber after BUBBLE SORT : \n"; | |
for(int i=0;i<14;i++){ | |
for(int j=0;j<14-i;j++){ | |
if(a[j]>a[j+1]){ | |
int t=a[j]; | |
a[j]=a[j+1]; | |
a[j+1]=t; | |
} | |
} | |
} | |
display(a); | |
getch(); | |
return(0); | |
} | |
void display(int b[]){ | |
for(int i=0;i<15;i++){ | |
cout<<b[i]<<" "; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment